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. Menubar in MacOS not working.

Menubar in MacOS not working.

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 5 Posters 3.5k 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.
  • D Offline
    D Offline
    DevinQT
    wrote on last edited by DevinQT
    #1

    Hey,

    I am following a beginner's course on Qt and tutors usage of the menubar functions do not work for on my Mac.

    I have looked on Google and the Qt documentation, but i could either not understand it, or it didn't work when i tried it. I need a really basic explanation.

    The report i found here (https://bugreports.qt.io/browse/QTBUG-57072) did solve it partially, but with that i could not pass an predefined Action variable in the addAction function.
    Side-question: I am also using the free Qt Creator 4.8.0 (Based on Qt 5.12.0). Is this a older version than the one in the report? (5.6) Or does the free version have another version count?

    The question is; how should this code be changed to get it to work with the Mac menubar?

    #include "mainwindow.h"
    #include <QPushButton>
    #include <QMenuBar>
    #include <QStatusBar>
    #include <QDebug>
    #include <QAction>
    #include <QApplication>
    
    MainWindow::MainWindow(QWidget *parent)
       : QMainWindow(parent)
    {
    
       //Add central widget
       QPushButton * button = new QPushButton("Hello",this);
       setCentralWidget(button);
    
    
       //Declare Quit Action
       QAction * quitAction = new QAction("Quit");
       connect(quitAction,&QAction::triggered,[=](){
           QApplication::quit();
       });
    
       //Add menus
       QMenu * fileMenu = menuBar()->addMenu("File");
       fileMenu->addAction(quitAction);
       menuBar()->addMenu("Edit");
       menuBar()->addMenu("Window");
       menuBar()->addMenu("Settings");
       menuBar()->addMenu("Help");
    }
    
    MainWindow::~MainWindow()
    {
    
    }
    
    
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What exactly does not work ?

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

      1 Reply Last reply
      0
      • D Offline
        D Offline
        DevinQT
        wrote on last edited by
        #3

        The menubar is empty.

        1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @DevinQT said in Menubar in MacOS not working.:

          • Side-question: I am also using the free Qt Creator 4.8.0 (Based on Qt 5.12.0). Is this a older version than the one in the report? (5.6) Or does the free version have another version count?

          QtCreator 4.8 is the newest version.
          They talk about Qt version 5.6, not QtCreator version.
          (the" based on" in About, is the Qt version used to compile Creator)

          You can use QtCreator with any version of Qt, even multiple versions.

          There is no difference between open source and commercial QtCreator.

          1 Reply Last reply
          2
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by SGaist
            #5

            Your menus are all empty. Add one or more actions to them and they will appear.

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

            1 Reply Last reply
            0
            • D Offline
              D Offline
              DevinQT
              wrote on last edited by DevinQT
              #6

              There is one action in the menu. "quitAction"
              I've added another action which is not a variable, but it doesn't show up.

              I have taken the source code produced by the lecture and run the exact same code:

              0_1548369588037_Screenshot 2019-01-24 at 23.38.41.png
              Left: my Qt window and my app. Right: the lecture.

              (sidenote: I have deleted the status bar tho, so not exactly the same code)

              1 Reply Last reply
              0
              • M Offline
                M Offline
                mpergand
                wrote on last edited by mpergand
                #7

                You need to populate the menus with some items:

                QMenu * menu = menuBar()->addMenu("File");
                menu->addAction(quitAction);
                
                menu=menuBar()->addMenu("Edit");
                QAction* action=menu->addAction(tr("Undo"));
                action->setShortcut(QKeySequence::Undo);
                
                menu=menuBar()->addMenu("Window");
                 action=menu->addAction(tr("window 1"));
                
                menu=menuBar()->addMenu("Settings");
                action=menu->addAction(tr("settings 1"));
                
                menu=menuBar()->addMenu("Help");
                action=menu->addAction(tr("help me !"));
                
                1 Reply Last reply
                1
                • D Offline
                  D Offline
                  DevinQT
                  wrote on last edited by DevinQT
                  #8

                  Thanks. That adds a few menu items. It skipped 'File' and 'Settings', but i guess there's a reason for that?

                  0_1548378091762_Screenshot 2019-01-25 at 01.55.49.png

                  SGaistS 1 Reply Last reply
                  0
                  • D DevinQT

                    Thanks. That adds a few menu items. It skipped 'File' and 'Settings', but i guess there's a reason for that?

                    0_1548378091762_Screenshot 2019-01-25 at 01.55.49.png

                    SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    Yes there is and it's all explained in QMenuBar's documentation.

                    Exit and settings action are moved to the "application name" menu on macOS.

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

                    1 Reply Last reply
                    2
                    • W Offline
                      W Offline
                      whitehouse_james
                      wrote on last edited by
                      #10

                      Working on same course, had same mac issue. Note: "quit" is not visible - by design - on a Mac. After a lot of searching, here is fix that works on both Linux and Mac:

                      ```
                      

                      // declare actions from .h
                      act_quit = new QAction("quit");
                      act_stop = new QAction("Stop");

                      // connect actions
                      QObject::connect(act_quit,&QAction::triggered,this,
                                       [=](){QApplication::quit();
                      });
                      
                      QObject::connect(act_stop,&QAction::triggered,this,
                                       [=](){QApplication::quit();
                      
                      });
                      
                      // add menus
                      QMenu *filemenu = menuBar()->addMenu("File");
                      filemenu->addAction(act_quit);
                      filemenu->addAction(act_stop);
                      
                      QMenu *mnu_other = menuBar()->addMenu("Other");
                      mnu_other->addAction(act_quit);
                      mnu_other->addAction(act_stop);
                      
                      QMenu *mnu_three = menuBar()->addMenu("hello");
                      mnu_three->addAction(act_quit);
                      mnu_three->addAction(act_stop);
                      
                      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