Native Menu bar on macOS
- 
How do I create an application that start with just a filled menu bar on macOS? The following code works with Qt 4.8.7, 5.3.2 and 5.5.1 but does not with 5.6.1, 5.6.2 and 5.7. #include <QApplication> #include <QMenuBar> #include <QMenu> int main(int argc, char *argv[]) { QApplication a(argc, argv); QMenuBar *m = new QMenuBar; QMenu *menu = new QMenu( "menu 1" ); menu->addAction( "action 1" ); menu->addAction( "action 2" ); m->addMenu( menu ); return a.exec(); }No menu is shown with Qt 5.6.1 and 5.6.2. 
- 
Hi, 
 you can try it this way:QMenuBar *m = new QMenuBar(0); QMenu *menu = m->addMenu( "menu 1" ); menu->addAction( "action 1" ); menu->addAction( "action 2" );-Michael. @m.sue 
 Explicitly specifying what is the default parent (0) ?
 Nah, I tried, even if I couldn't see how that would help.
- 
Hi, Which version of macOS are you running on ? 
- 
@SGaist 
 I tried 10.9, 10.11 and 10.12. This seems irrelevant to the problem.
- 
@SGaist 
 I tried 10.9, 10.11 and 10.12. This seems irrelevant to the problem.workaround: #include <QApplication> #include <QMenuBar> #include <QMenu> int main(int argc, char *argv[]) { QApplication a(argc, argv); QMenuBar *m = new QMenuBar; QMenu *menu = new QMenu( "menu 1" ); menu->addAction( "action 1" ); menu->addAction( "action 2" ); m->addMenu( menu ); m = new QMenuBar; // <-- Qt5.6, this seems to force the previous menu to show up m->deleteLater(); return a.exec(); }
- 
@m.sue 
 Explicitly specifying what is the default parent (0) ?
 Nah, I tried, even if I couldn't see how that would help.@sandy.martel23 said in Native Menu bar on macOS: even if I couldn't see how that would help I did just copy what works here. 
 Maybe the Application needs to have a QMainWindow. At least, we call the code inside a QMainWindow derived class.
 -Michael.
- 
@sandy.martel23 said in Native Menu bar on macOS: even if I couldn't see how that would help I did just copy what works here. 
 Maybe the Application needs to have a QMainWindow. At least, we call the code inside a QMainWindow derived class.
 -Michael.@m.sue 
 Yes Qt5 seems to require a window to show up as the application starts. Anyway, my workaround works.
- 
