Qt 5.8 : Main menu items disabled in OSX



  • I downloaded Qt 5.8 for Mac, test it with an application that works well with Qt 5.7.1 and there are incredible bugs with the main menu !

    menu bugs

    Menus with submenu are disabled (Bookmarks, History in the first image)

    Once a window is closed, the application menu items are disabled (Quit, About, Preferences in the second image above)

    Maybe this bug is related to [QTBUG-54845](https://bugreports.qt.io/browse/QTBUG-54845?jql=text ~ %22menu disabled%22)
    Currently, I'm using Qt 5.6.1 and 5.7.1 with Mac OSX 10.9.5 Mavericks and never seen this kind of bugs !

    I have to use Qt 5.8 because I want to experiment QtWebkit tp5 that needs it.
    Any help would be appreciated.


  • Lifetime Qt Champion

    Hi,

    Can you provide a minimal compilable sample application that shows that behaviour ?

    Also, which version of macOS are you running ?



  • Hi @SGaist

    I'm on OSX 10.9.5 Mavericks
    I'm using Qt since 5.3 and manege the main menu in the same maner without troubles.
    In 5.8 it doesn't work any more !

    I construct the Quit menu like this:

    action=menu->addAction(tr("Quit"));
     action->setMenuRole(QAction::QuitRole);
     action->setShortcut(QKeySequence::Quit);
    

    If I comment the line action->setMenuRole(QAction::QuitRole);
    It becomes active again !
    But that doesn't work for About and About Qt, if you don't specify the role this two menus don't appear.

    The Apple menu is totally broken in Qt 5.8
    I'm looking to use real native Cocoa menu, if it's possible ...


  • Lifetime Qt Champion

    Can you check if it still happening with 5.9 ?

    And again, can you give a complete minimal example ? That way it makes it possible to reproduce the problem the same way it happens to you.



  • @SGaist said in Qt 5.8 : Main menu items disabled in OSX:

    Can you check if it still happening with 5.9 ?

    And again, can you give a complete minimal example ? That way it makes it possible to reproduce the problem the same way it happens to you.

    Here it is:

    #include <QApplication>
    #include <QMainWindow>
    #include <QMenu>
    #include <QMenuBar>
    
    class Application : public QApplication
    {
        public:
    
            Application( int &argc, char **argv ) : QApplication(argc, argv) {}
    
            QMenuBar* createMenuBar()
                {
                QMenuBar* menuBar=new QMenuBar(0);
                QMenu* menu=menuBar->addMenu("File");	// menu Fichier
                QAction* action=menu->addAction("Quit");
                action->setShortcuts(QKeySequence::Quit);
                action->setMenuRole(QAction::QuitRole);
                connect(action, SIGNAL(triggered()), this, SLOT(quit()));
                return menuBar;
                }
    };
    
    
    int main(int argc, char *argv[])
    {
        Application app(argc, argv);
        app.setQuitOnLastWindowClosed(false);
        
        // create a menubar for OSX only, when no window was opened
        // here is the bug with Qt 5.8
        // if I comment this line the Quit menu is disabled in 5.6/5.7
        // in 5.8 it's always disabled as soon as  a window is closed
        app.createMenuBar();
    
        QMainWindow* win=new QMainWindow;
        win->setAttribute(Qt::WA_DeleteOnClose);
        win->setMenuBar(app.createMenuBar());   // create menubar for this window
        win->show();
    
        return app.exec();
    }
    


  • Well, there's a mess with the parentless menuBar, you need to recreate it each time you create a new window:

    int main(int argc, char *argv[])
    {
        Application app(argc, argv);
        app.setQuitOnLastWindowClosed(false);
    
        // create a menubar for OSX only, when no window was opened
        app.createMenuBar();
    
        QMainWindow* win=new QMainWindow;
        win->setAttribute(Qt::WA_DeleteOnClose);
        win->setMenuBar(app.createMenuBar());   // create menubar for this window
        win->show();
        
        app.createMenuBar();  // recreate
    
        QMainWindow* win2=new QMainWindow;
        win2->setAttribute(Qt::WA_DeleteOnClose);
        win2->setMenuBar(app.createMenuBar());   // create menubar for this window
        win2->show();
        
        app.createMenuBar(); // recreate
    
        return app.exec();
    

    }

    Now the quit menu is active in all cases: if you close the first window or the two windows.

    Regardless this bug, the submenu issue seems unrelated, if I add the following in the createMenuBar:

    action=menu->addAction(tr("Open Recent"));
    action->setMenu(new QMenu(menuBar));
    action->menu()->setEnabled(true);
    

    The submenu Open Recent is disabled.
    In Qt 5.6.1/5.7.1 it's enabled.

    Referring to the bug report QTBUG-54845, it seems the patch was not apply to 5.8, right ?


  • Lifetime Qt Champion

    From the bug report the fix has been applied to 5.6.2 so it's also valid for further versions of Qt.

    It seems we have here something new.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.