How to correctly assign a QMenu to QAction in Qt 6.2?
Unsolved
General and Desktop
-
Hey guys,
I'm porting my project from Qt 5.15.2 to Qt 6.2.4.
So, in my code, I have a lot of
QAction
instances that make use ofQMenu
for dynamic submenus configuration depending on the user's input like this:q_menu->addAction(act); q_menu->addAction(act1); q_menu->addAction(act2); ... q_action->setMenu(q_menu);
Reading the docs, I found that
QAction::setMenu()
andQAction::menu()
are deprecated, this way my code is failing to build again! :(My question is, what's the correct way to assign a menu to an action? Couldn't find anything that could give me some direction.
I hope you can give me some hints!
Thanks in advance. -
Hi,
From a quick look at the QMenu documentation, I would say you shall use QMenu::menuAction.
So build your "sub-menu" and retrieve its action to store it in "q_action".