Results 1 to 5 of 5

Thread: Communication between QRunnable and main thread

  1. #1
    Join Date
    Dec 2008
    Location
    Paris, France
    Posts
    34
    Thanks
    3
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Question Communication between QRunnable and main thread

    Hi all,

    To tell the user that the QRunnable threads have not stalled, I would like them to provide some feedback to the main GUI. But QRunnable does not inherit QObject, hence doesn't seem to provide the capability of signal emission.
    So, how can a QRunnable thread communicate to the main thread ?

    Thanks

    Andre

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,708
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Communication between QRunnable and main thread

    I see two options for signaling from a QRunnbale:
    1. Since QRunnable is not a QObject, you can multiple inherit from QObject:
    Qt Code:
    1. class MyRunnable : public QRunnable, public QObject
    2. {
    3. ...
    4. };
    To copy to clipboard, switch view to plain text mode 

    Note - at least in theory - I didn't try it.

    The other option is to have a member in your QRunnable which is a QObject, and signal from that object.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Dec 2008
    Location
    Paris, France
    Posts
    34
    Thanks
    3
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Communication between QRunnable and main thread

    I'll try, thanks

  4. #4
    Join Date
    Dec 2008
    Location
    Paris, France
    Posts
    34
    Thanks
    3
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Communication between QRunnable and main thread

    Just for information, I found a way using postEvent() from the QRunnable thread to the main thread.

  5. #5
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,708
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Communication between QRunnable and main thread

    Yes, that is true, you can always send an event, and before Qt4.X that was the only way to "signal" between threads (signals where not possible)
    But you asked about sending signals, so...
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. Replies: 9
    Last Post: 28th November 2009, 21:31
  2. Replies: 16
    Last Post: 7th October 2009, 09:17
  3. Replies: 6
    Last Post: 29th April 2009, 19:17
  4. Thread Communication not doing so well
    By BatteryCell in forum Qt Programming
    Replies: 7
    Last Post: 19th June 2007, 02:08
  5. Main thread - worker thread communication.
    By kikapu in forum Newbie
    Replies: 25
    Last Post: 23rd May 2007, 23:09

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.