Results 1 to 2 of 2

Thread: using invokeMethod for menu addAction

  1. #1

    Default using invokeMethod for menu addAction

    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
    Qt Code:
    1. blah = ui->menuCurves->addAction("ActionText");
    To copy to clipboard, switch view to plain text mode 
    with this code
    Qt Code:
    1. QMetaObject::invokeMethod(ui->menuCurves, "addAction",
    2. Qt::QueuedConnection, Q_RETURN_ARG(QAction*, blah), Q_ARG(QString, "ActionText"));
    To copy to clipboard, switch view to plain text mode 

    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???

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: using invokeMethod for menu addAction

    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).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Problems with QMetaObject::invokeMethod
    By AlphaWolf in forum Qt Programming
    Replies: 3
    Last Post: 13th September 2012, 12:57
  2. QMenu and addAction problem
    By .:saeed:. in forum Newbie
    Replies: 0
    Last Post: 20th January 2011, 10:04
  3. Replies: 4
    Last Post: 16th September 2010, 17:24
  4. Replies: 12
    Last Post: 21st November 2008, 05:42
  5. How to use QMetaObject::invokeMethod?
    By niko in forum Qt Programming
    Replies: 3
    Last Post: 26th January 2008, 17:02

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.