Results 1 to 2 of 2

Thread: Invoke slot from a non-QThread

  1. #1
    Join Date
    Jan 2013
    Posts
    16
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Android

    Default Re: Invoke slot from a non-QThread

    I have a callback made from another (non-Q)Thread that I need to interact with the UI. I've tried having the callback start a QTimer and invoke a slot, but I get an error explaining that I can't use QTimer in a non-QThread. What other options do I have?


    Added after 31 minutes:


    This works:

    timer->moveToThread( QApplication::instance()->thread() );

    and also, when calling connect(), pass Qt::QueuedConnection, as in:

    connect( timer, SIGNAL(timeout()), this, SLOT(update()), Qt::QueuedConnection );
    Last edited by stephelton; 14th January 2013 at 08:09.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Invoke slot from a non-QThread

    You can always invoke a slot using QMetaObject::invokeMethod() without having to be in the context of a QObject
    If you do this on a GUI object from a non-GUI thread, then use Qt::QueuedConnection as the Qt::ConnectionType argument of invokeMethod()

    Cheers,
    _

Similar Threads

  1. QThread slot executed in GUI thread
    By tnyblom in forum Qt Programming
    Replies: 13
    Last Post: 25th May 2010, 07:49
  2. QThread::start() doesn't invoke run() method
    By seim in forum Qt Programming
    Replies: 2
    Last Post: 5th February 2009, 17:09
  3. what if qthread call same slot at the same time?
    By zl2k in forum Qt Programming
    Replies: 2
    Last Post: 11th September 2008, 09:58
  4. my SLOT not part of QThread
    By freak in forum Newbie
    Replies: 6
    Last Post: 16th June 2006, 20:17
  5. Invoke a slot by its name in QString...
    By sunil.thaha in forum Qt Programming
    Replies: 4
    Last Post: 6th April 2006, 09:28

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.