Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Mac, 4.8.5: QAction in main menu not obeying AboutRole menu role [Solved]
when triggering the "About..." item in the Applications menu, the corresponding slot does not get called; instead a completely unrelated slot gets called.
In Qt Creator, the menu item resides under the "Help" menu. On the Mac, menu items with the role QuitRole, AboutRole or PreferencesRole is automatically moved to the Applications menu, which does not happen for the AboutRole in my case. I still see the menu item under the "Help" menu, and here the correct slot is called. The other roles works as expected.
I quadruple checked, and the QAction in question does have role set as AboutRole, see below.
It's an application ported from 5.2, and as I recall, it worked in 4.8.4. I don't have the opportunity to test in 4.8.4.
Edit: Snippet from the .ui file defining the QAction. I can't see any funkiness compared to the others:
I'm not sure I am following you properly so:
It's working properly with Qt 4.8.4 but not 4.8.5, is that right ?
I have rewritten my post. It was late.
As I recall, yes, but it's been a while. At least it worked in 5.x.
Just tried with a little dummy app but it seems to be working. Do you have a minimal example that I could try ?
Just tried the same; works in a new project. I'll try to boil my project down to a minimal main window example.
Found the problem. As per http://qt-project.org/doc/qt-4.8/qmenubar.html#qmenubar-on-mac-os-x , menu item texts containing the string "about*" automatically gets assigned the menu role, and moved to the "appropriate" place. The problem is, my application is a browser-like application with dynamically loaded browser bookmark and history menus. Guess what? Some of the items were from "about.com", which explains that when I triggered the "About..." menu item, the page from about.com gets loaded. Sort of explains everything.
But - both QAction::setMenuRole(QAction::NoRole) and QAction::setMenuRole(QAction:: TextHeuristicRole) on the dynamic items are being ignored. They are still triggered by the "About..." menu item.
I'm pretty sure this was ok in Qt4.8.4.
Am I overseeing something here? I just need ONE Qt version that works properly on the Mac, then I would be happy. If I'm not overseeing something, then I'm out options, and will start porting my application to pure c or assembly language. That would probably be less frustrating.
Can you post a minimal QAction setup that shows this behavior ?
Nope, thankfully :-D
Created a minimal example, turns his the menu role HAS to be QAction::NoRole, QAction::TextHeuristicRole won't cut it. Once I changed this consistently in my application, it worked.
Great ! :)
Thanks for sharing the solution.
You could add a doc note on QAction explaining this, that might help others :)
Done for 4.8 :-)
Nice, thank you !