Qmenu::findChild is not working properly
-
Hi All
The QMenu findChild is not working properlyQMenu* lMenu;
QMenu* existingMenu = lMenu->findChild<QMenu*>(QString("A..."));
if (!existingMenu)
lMenu->addMenu("A...");Can someone help me to solve the same . In this case existing menu is always NULL athat is why A... gets added multiple times
-
Hi All
The QMenu findChild is not working properlyQMenu* lMenu;
QMenu* existingMenu = lMenu->findChild<QMenu*>(QString("A..."));
if (!existingMenu)
lMenu->addMenu("A...");Can someone help me to solve the same . In this case existing menu is always NULL athat is why A... gets added multiple times
@Qt-Enthusiast said in Qmenu::findChild is not working properly:
findChild
the string you define in
findchild
specifies the objectname. Newly, by code not designer, created Objects have an empty string as ObjectName. -
could you please code for me
-
untested.
QMenu* lMenu; QMenu* existingMenu = lMenu->findChild<QMenu*>(QString("A...")); if (!existingMenu){ existingMenu = new QMenu("A..."); existingMenu->setObjectName("A..."); lMenu->addMenu(existingMenu); }
-
could you please code for me
@Qt-Enthusiast said in Qmenu::findChild is not working properly:
could you please code for me
Could you please read documentation: http://doc.qt.io/qt-5/qobject.html#objectName-prop ?