Solved Menu from the action
-
i'm adding a QMenus to a QWidget, but then when i try to find a menu with the given title, i get nullptr. here's how i'm doing it:
for(auto action : widget->actions()) { QMenu *menu = action->menu(); if(menu && menu->title() == title) return menu; } return nullptr;
what is wrong?
-
@user4592357
What does this output? Is the title you're looking for there?for(auto action : widget->actions()) { QMenu *menu = action->menu(); if (menu) qDebug() << menu->title(); if(menu && menu->title() == title) return menu; } return nullptr;
-
i'd tried that. menu is nullptr
-
@user4592357
and what did
qDebug() << menu->title();show/list ?
-
i didn't try that but how could that work if menu was nullptr?
actually i solved this by getting action's widget and then getting widget's menu and comparing that menu's title to the input title
-
@user4592357 Maybe it isn't null but the title is different to what you are searching?
-
i figured out what why menu was nullptr. i actually called setMenu() on action's widget, not on actual action, so now i set the menu to the action and the loop works correctly