Mac Menus are not active ????



  • Built an App on Window and tested on Linux and both work, but on moving to Mac OSX and running the Main Mac Menu is not active and will not become active until i change focus to another application and back to the Qt app. I've tried Debug, Release and all have the same behavior. Currently only 2 menu items. The standard Mac menu with Quit in it built by Qt, and one that I've created. Both are inactive at startup.

    Sorry if this is dumb question, I'm learning Qt


  • Lifetime Qt Champion

    Hi,

    Which version of Qt are you using ? On which version of OS X ?



  • Qt 5.7 and Mac OSX 10.11.6



  • This is a construction menu if that makes a differnce

                MenuInfo menuInfo = itMenu.next();
                QString menuTitle = menuInfo.getTitle();
                if (!menuTitle.isEmpty())
                {
                    QAction * menuAction = new QAction(this);
                    menuAction->setData(menuInfo.getFormId());
                    menuAction->setText(menuTitle);
                    menuAction->setToolTip(menuInfo.getDescription());
                    menuAction->setStatusTip(menuInfo.getDescription());
                    mainMenu->addAction(menuAction);
                    connect(menuAction, &QAction::triggered, this, &MainWindow::openForm);
                }


  • I am surprised this hasn't got more responses. This is an obvious bug in Qt, after further playing with it, and compromises Qt's Cross platform claim. Is there a way to debug Qt source on this ?


  • Lifetime Qt Champion

    Sorry, I missed your answer.

    I can't reproduce your problem because in the code you provided there are unknown elements: MenuInfo, itMenu and mainMenu.

    Sure you can debug Qt, the source is freely available either be cloning it with git or downloading the sources from the version you installed on your computer.

    Before stating that there is an obvious bug, please provide a minimal compilable example that reproduce the behavior.

    Also, please note that this forum is community driven so there might not be many people here having the same hardware/OS version as you at hand.



  • i understand that this is a community forum, but a bug that compromises cross platform to Mac would seem to be of huge concern . I did some researching and it seems that this problem was reported in 4.8. I can't find it right now, when I do I'll give a link. Apparently, it's been around for awhile, yet still alive and well.



  • I haven't noticed this problem (I currently use Qt 5.6.0, OS X 10.10.5, XCode 7.2.1). It could be something new with Qt 5.7.x but I hadn't seen anything like this in previous versions (your hint that it might have existed since 4.8.x). I don't use a lot of menu's or complex menus but I do have menu's in some applications and they do work (I even double checked to make sure). I have never had an issue running these on any version of OS X that I have had (snow leopard and up) or at least anything that was noticable.

    As @SGaist mentioned can you provide a minimal example showing this problem.

    In your sample code is it possible that 'menuTitle' is an empty string in some cases and maybe this is why the menu is not constructed?.

    MenuInfo menuInfo = itMenu.next();
    QString menuTitle = menuInfo.getTitle();
    if (!menuTitle.isEmpty())
    {
       // create menu skipped if menuTitle is empty
    }
    


  • I too have an application that runs on Mac and Windows and have never seen the behaviour you describe. As other folks have said it may be a 5.7 regression but it must have been fixed since 4.8 or Rondog and I (and probably many others) would surly have noticed it.

    As Rondog and SGaist suggest, you should show more code so we can reproduce the issue. It is better to provide a minimum app with a main window and the menus set up the way your app does it.

    Do you get the same problem when you build the MainWindow example or the Menus example for instance?



  • @Rondog

    @Rondog said in Mac Menus are not active ????:

    I haven't noticed this problem (I currently use Qt 5.6.0, OS X 10.10.5, XCode 7.2.1). It could be something new with Qt 5.7.x but I hadn't seen anything like this in previous versions (your hint that it might have existed since 4.8.x). I don't use a lot of menu's or complex menus but I do have menu's in some applications and they do work (I even double checked to make sure). I have never had an issue running these on any version of OS X that I have had (snow leopard and up) or at least anything that was noticable.

    As @SGaist mentioned can you provide a minimal example showing this problem.

    In your sample code is it possible that 'menuTitle' is an empty string in some cases and maybe this is why the menu is not constructed?.

    MenuInfo menuInfo = itMenu.next();
    QString menuTitle = menuInfo.getTitle();
    if (!menuTitle.isEmpty())
    {
       // create menu skipped if menuTitle is empty
    }
    

    The menu is constructed and displayed. It's just inactive until clicking on another program and then back to the this Qt app. It only has 2 menu items the default one on Mac and the one created in code.


  • Lifetime Qt Champion

    Then, please, provide us the means to reproduce that situation.

    We are already several people not getting that problem. Therefore without your code we cannot help to either find the bug that you might have uncovered in Qt or find the one that you have in your application.



  • I'm trying to put something together. It seems like if I have a .ui file for the mainwindow and use the ui-> things seem to work, if I don't then that's when the problems seem to appear. I'm trying to make a small example.



  • I have tried to reproduce this problem with smaller subsets of code and cannot. I not really sure how to debug this problem.

    I've rebuilt the project from scratch adding items and testings as I went along. Everything worked fine up the the point of adding a resource file .

    Currently I have only the default Mac menu item, everything else is on the toolbar and working. All the application works except for the menu being dead until clicking on another program and then back.


  • Qt Champions 2016

    @Nevering
    If you have a sample that can be built and tested,
    please upload to git or any other site where
    its easy for people to get it as one zip/together easy to run project.

    That way its very likely that others will try your test program and we can find out if
    its just on your system or its actually a Qt bug :)



  • I was able to reproduce this in a small test project. I don't see a way of uploading a zip file



  • @Nevering

    Once your menubar is created, add those 2 lines:

    // Qt5.6: this seems to force the previous menubar to show up and activate
    auto m = new QMenuBar; 
    m->deleteLater();
    

    This create another parentless top-level menubar and delete it later. I've been debugging through Qt's macOS menu handling code and it seems to have changed a lot between Qt5.5 and Qt5.6. This code triggers the native menu bar synchronisation that used to happen automatically. Looks like they screw this up for 5.6.



  • Thanks for the answer, but that didn't help.. Still got a hang



  • added it like this

    ui->setupUi(this);
    QPixmap pix(":/images/user.png");
    QIcon ico(pix);
    ui->toolButton->setIcon(ico);
    
    auto m = new QMenuBar;
    m->deleteLater();
    

    I'll try again after the ui->setup



  • Same thing



  • @Nevering
    A test project would be great.



  • I think I've added the code here ??
    https://github.com/Nevering/Splitters.git



  • @Nevering
    "This repository is empty."



  • There now, please try again
    learning github



  • @Nevering
    Well, it's pretty simple in your case, don't do:

    CONFIG -= app_bundle
    


  • why ?

    If I don't the files in the subdirectories are not found



  • Well not found in my actual application. that has sever folders were files are being used for building aspects of the application.



  • @Nevering said in Mac Menus are not active ????:

    why ?

    Gui applications on Mac are bundles.

    If I don't the files in the subdirectories are not found

    Look at how to embed resources, either the Qt way, with the 'Qt Resource Compiler' or the Mac's way with bundle resources.

    If you really want to keep those as external files you'll need to adjust the relative path on Mac.



  • is this a good reference, or is there a better one, this is from 4.8.

    http://doc.qt.io/qt-4.8/deployment-mac.html



  • I ran a test and saw exactly what you described in this thread (Qt 5.6.0, OSX 10.10.5, XCode 7.2.1). I tried changing a few things here and there in the source to see if I could get it to work without success. Changes in the PRO file seemed to affect it.

    In the project file I remove this line:

    CONFIG -= app_bundle
    

    and replaced it with this:

    CONFIG +=release \
    		warn_on \
    		qt \
    		thread 
    

    It worked fine after this change for some reason.

    I didn't look into what the differences are in these options of the project file. These are common options I use for everything. Maybe try this and see if this works for you as well.

    I also tried converting the UI file into a set of cpp files (generic main.cpp, mainwindow.cpp, and mainwindow.h). It worked regardless of the above change in the PRO file.

    It looks like there is something odd going on but I am not sure what the source is. The project file supplied with this sample should be cleaned up regardless (maybe this is the underlying reason?). The project file from the CPP generated version is a little more complete so this could be a reason I didn't see this problem with the derived version and only with the UI version (?).



  • Someone please help me understand the problem. Why did CONFIG -= app_bundle cause the problem and removing fix it? The article linked above says that CONFIG -= app_bundle should be used for Macs .



  • @Rondog

    So the article that I linked says that CONFIG -= app_bundle is needed on Mac.. Is this not the case ? Is there any more recent documentation on how to build the bundle within Qt?


  • Lifetime Qt Champion

    You misunderstood the documentation. As stated just about the code snippet, the CONFIG -= app_bundle line applies only to command line tools.

    Otherwise, use a bundle. macOS looks for information in that bundle: the Info.plist file being the central point of interest. Qt generates one for you automatically with sensible defaults.

    Depending on what feature you'll be using, you will have to provide your own file.



  • Trying to find out more, but I don't see any info.plist created with any of my projects built on my Mac.


  • Lifetime Qt Champion

    Where did you look for it ?



  • @SGaist

    I saw it in the Mac documentation.. And I did a search on my Mac. There doesnt' seem to be any related info.plist file generated in the local folder. However there are some on the system and in the Qt example folder. Still trying to figure this out, documentation on this would really help ...


  • Lifetime Qt Champion

    The Info.plist file can be found in ./your_application_name.app/Contents/.



  • Are you saying it's inside the .app file ? Other info.plist that I have seperate files, for example in the one in Examples/Qt-5.7/sensors/accelbubble.


  • Lifetime Qt Champion

    Yes it is.

    When you see an Info.plist file in an example sources or another project it's because it has been customized. You can check in the .pro file and you'll find line stating that it's the one that should be used and which will be copied into the bundle.



  • @Nevering
    It looks like you need to read up on the Mac docs about how prepare an app for deployment. A .app file is just a directory with a special name that the mac understands and expects to contain certain files and directories. Just open one up and take look inside you will see. You will find the rules in the mac documentation.
    if you have XCode or access to the apple developer site you might look at [this]
    (https://developer.apple.com/library/content/documentation/CoreFoundation/Conceptual/CFBundles/Introduction/Introduction.html#//apple_ref/doc/uid/10000123i)

    The macdeployqt tool will build one for your app and you can modify it to suit your needs. The document you linked in you previous post tells you how to do that.

    Good luck



  • I've had a similar bad experience since 5.7 on macos 10.11 and now 10.12. I too have to focus to another app after the qt application starts. If I don't, the push buttons are not clickable, and even a native mac file dialog won't allow me to select files, though the scrollers work (I invoke the dialog with a shortcut). This applies to running the app from qtcreator, however, when run from terminal or a proper .app bundle, it works as expected.


Log in to reply
 

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