PDA

View Full Version : using invokeMethod for menu addAction



dwizard
27th June 2013, 04:38
For various reasons I would like to move my creation of menu actions to a thread. I thought I should be able to do this with "invokeMethod", but I am having problems.

Essentially, I would like to replace this code
blah = ui->menuCurves->addAction("ActionText"); with this code
QMetaObject::invokeMethod(ui->menuCurves, "addAction",
Qt::QueuedConnection, Q_RETURN_ARG(QAction*, blah), Q_ARG(QString, "ActionText"));

Using invokeMethod, the code runs but 'blah' is not a valid pointer and nothing is added to the 'menuCurves' menu.

I feel like I am close, but what is wrong???

wysota
27th June 2013, 06:31
Using invokeMethod() with Qt::QueuedConnection does not do anything in a thread. It is just a delayed invokation. And I don't see how you'd like to access that "blah" pointer since it will only be valid after the method is executed (and only if you made the method a slot or otherwise invokable).