Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Native Menu bar on macOS

Native Menu bar on macOS

Scheduled Pinned Locked Moved Unsolved General and Desktop
mac osqt5.6
9 Posts 3 Posters 4.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sandy.martel23
    wrote on 13 Oct 2016, 05:32 last edited by sandy.martel23
    #1

    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.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      m.sue
      wrote on 13 Oct 2016, 06:58 last edited by
      #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.

      S 1 Reply Last reply 13 Oct 2016, 20:55
      0
      • M m.sue
        13 Oct 2016, 06:58

        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.

        S Offline
        S Offline
        sandy.martel23
        wrote on 13 Oct 2016, 20:55 last edited by
        #3

        @m.sue
        Explicitly specifying what is the default parent (0) ?
        Nah, I tried, even if I couldn't see how that would help.

        M 1 Reply Last reply 14 Oct 2016, 09:49
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 13 Oct 2016, 21:15 last edited by
          #4

          Hi,

          Which version of macOS are you running on ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          S 1 Reply Last reply 14 Oct 2016, 00:58
          0
          • S SGaist
            13 Oct 2016, 21:15

            Hi,

            Which version of macOS are you running on ?

            S Offline
            S Offline
            sandy.martel23
            wrote on 14 Oct 2016, 00:58 last edited by
            #5

            @SGaist
            I tried 10.9, 10.11 and 10.12. This seems irrelevant to the problem.

            S 1 Reply Last reply 14 Oct 2016, 01:07
            0
            • S sandy.martel23
              14 Oct 2016, 00:58

              @SGaist
              I tried 10.9, 10.11 and 10.12. This seems irrelevant to the problem.

              S Offline
              S Offline
              sandy.martel23
              wrote on 14 Oct 2016, 01:07 last edited by
              #6

              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();
              }
              
              1 Reply Last reply
              0
              • S sandy.martel23
                13 Oct 2016, 20:55

                @m.sue
                Explicitly specifying what is the default parent (0) ?
                Nah, I tried, even if I couldn't see how that would help.

                M Offline
                M Offline
                m.sue
                wrote on 14 Oct 2016, 09:49 last edited by
                #7

                @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.

                S 1 Reply Last reply 16 Oct 2016, 22:32
                0
                • M m.sue
                  14 Oct 2016, 09:49

                  @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.

                  S Offline
                  S Offline
                  sandy.martel23
                  wrote on 16 Oct 2016, 22:32 last edited by
                  #8

                  @m.sue
                  Yes Qt5 seems to require a window to show up as the application starts. Anyway, my workaround works.

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    sandy.martel23
                    wrote on 10 Nov 2016, 23:10 last edited by
                    #9

                    https://bugreports.qt.io/browse/QTBUG-57072

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved