Results 1 to 4 of 4

Thread: QT3 -- How does a gui communicate with a worker thread?

  1. #1
    Join Date
    May 2010
    Posts
    24
    Thanks
    14
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Question QT3 -- How does a gui communicate with a worker thread?

    QT3 -- How does a gui communicate with a worker thread?

    I have a simple gui that creates and then launches a thread (derived from QThread). The thread does some continuous processing and remains for the life of the gui. In order for the thread to communicate with the gui, I use postevent -- which, as I understand, is the correct way for a thread to communicate with the gui.

    However, I am not sure how to safely communicate from the gui to the thread. Right now, I am directly accessing member functions/variables of my derived thread class (since the gui created/launched it). This method isn't safe, right?

    What is the "official" way for the gui to communicate with a thread? (Note: I am stuck using QT3)

    Thank You!

  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: QT3 -- How does a gui communicate with a worker thread?

    Quote Originally Posted by Ronayn View Post
    QT3 -- How does a gui communicate with a worker thread?
    Using events.

    I have a simple gui that creates and then launches a thread (derived from QThread). The thread does some continuous processing and remains for the life of the gui. In order for the thread to communicate with the gui, I use postevent -- which, as I understand, is the correct way for a thread to communicate with the gui.
    That's correct.

    However, I am not sure how to safely communicate from the gui to the thread.
    Basically, you can't. You can only use mutexes and a shared variable. Hard to call that "communication" though.
    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.


  3. #3
    Join Date
    May 2010
    Posts
    24
    Thanks
    14
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QT3 -- How does a gui communicate with a worker thread?

    Wysota, your first answer contradicts your third. To be crystal on this point, a QThread can use events to communicate (one-way) to the gui, but the gui cannot post events to the QThread (because it doesn't have an event loop). That is correct, yes?

    So, you are saying QT3 doesnt provide a safe way for the gui to communicate to a QThread? If so, that's a bummer

    Does QT4? (if you know)

  4. #4
    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: QT3 -- How does a gui communicate with a worker thread?

    Quote Originally Posted by Ronayn View Post
    Wysota, your first answer contradicts your third.
    No, it doesn't
    To be crystal on this point, a QThread can use events to communicate (one-way) to the gui, but the gui cannot post events to the QThread (because it doesn't have an event loop). That is correct, yes?
    Yes, only one-way communication is safe in Qt3.

    So, you are saying QT3 doesnt provide a safe way for the gui to communicate to a QThread? If so, that's a bummer
    Not anything built-in. You can only use a mutex, have a queue of messages and periodically check the queue from within the thread.

    Does QT4? (if you know)
    Yes, in Qt4 you can use signals and slots and events (both ways).
    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.


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

    Ronayn (21st September 2011)

Similar Threads

  1. Worker thread
    By doggrant in forum Newbie
    Replies: 4
    Last Post: 3rd November 2009, 16:49
  2. Worker thread problem
    By hkvm in forum Qt Programming
    Replies: 4
    Last Post: 6th September 2009, 21:12
  3. Showing progress bar while worker thread works
    By olidem in forum Qt Programming
    Replies: 6
    Last Post: 27th April 2009, 21:43
  4. Accessing data from a worker thread
    By steg90 in forum Qt Programming
    Replies: 20
    Last Post: 25th May 2007, 11:20
  5. Main thread - worker thread communication.
    By kikapu in forum Newbie
    Replies: 25
    Last Post: 23rd May 2007, 23:09

Tags for this Thread

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.