Results 1 to 4 of 4

Thread: How to use QMetaObject::invokeMethod?

  1. #1
    Join Date
    Jan 2006
    Posts
    105
    Thanks
    21
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How to use QMetaObject::invokeMethod?

    my testcase:
    Qt Code:
    1. class test : public QObject
    2. {
    3. Q_OBJECT
    4. public slots:
    5. void foo() {
    6. qDebug() << "foo called";
    7. }
    8. };
    9.  
    10. int main(int argc, char** argv)
    11. {
    12. QApplication app(argc,argv);
    13. test* x = new test;
    14. x->foo(); //works
    15. QTimer::singleShot(0, x, SLOT(foo())); //works
    16. QMetaObject::invokeMethod(x, SLOT(foo())); //doesn't work
    17. app.exec();
    18. }
    19. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 

    what's wrong? Why doesn't this work? (invoceMethod returns false - which means that the method is not found)

    thanks,
    niko

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,518 Times in 1,388 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to use QMetaObject::invokeMethod?

    Qt Code:
    1. QMetaObject::invokeMethod(x, "foo");
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  3. The following user says thank you to jpn for this useful post:

    niko (26th January 2008)

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

    Default Re: How to use QMetaObject::invokeMethod?

    Try without the SLOT() macro.

  5. The following user says thank you to wysota for this useful post:

    niko (26th January 2008)

  6. #4
    Join Date
    Jan 2006
    Posts
    105
    Thanks
    21
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to use QMetaObject::invokeMethod?

    of course - it all is written in the docs

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.