Results 1 to 3 of 3

Thread: QThread

  1. #1
    Join Date
    Sep 2006
    Posts
    46
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    2
    Thanked 3 Times in 2 Posts

    Default QThread

    Is there any simple way to wakeup a thread from QThread::msleep().

    Using QTimer as a single shot and putting the thread in a while loop looking for a close and cleanup call seems like more system overhead while QTimer::start() only has an integer resolution and QThread::msleep() has unsigned long being another caveat. I could piggyback QTimers but it would just be more kludged code.

    I noticed I can call QThread::terminate but from the docs it does not appear to let me clean up the thread in any way.

    Any suggestions on the best way to implement a thread that has a sleep condition and still be able to interrupt and cleanup the thread at any point?

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

    Default Re: QThread

    Quote Originally Posted by merlvingian View Post
    Is there any simple way to wakeup a thread from QThread::msleep().
    There is no way of waking a thread from a sleep.

    Using QTimer as a single shot and putting the thread in a while loop looking for a close and cleanup call seems like more system overhead while QTimer::start() only has an integer resolution and QThread::msleep() has unsigned long being another caveat. I could piggyback QTimers but it would just be more kludged code.
    Maybe you could use a QWaitCondition instead?

  3. #3
    Join Date
    Jun 2006
    Posts
    6
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    1

    Default Re: QThread

    I'm not sure what you are trying to do, but you could call QApplication:: processEvents() in a loop and just check a flag that you can set or clear from another thread to break out of the loop when you are ready.

Similar Threads

  1. How can I get the thread ID out of QThread
    By Artschi in forum Qt Programming
    Replies: 9
    Last Post: 8th November 2017, 04:27
  2. QThread call-once semantics?
    By brcain in forum Qt Programming
    Replies: 5
    Last Post: 20th October 2006, 22:25
  3. how to use QHttp inside QThread in Qt3
    By alusuel in forum Qt Programming
    Replies: 3
    Last Post: 14th July 2006, 12:19
  4. Replies: 4
    Last Post: 10th May 2006, 23:37
  5. Is it possible to create a QThread without inheriting ?
    By probine in forum Qt Programming
    Replies: 6
    Last Post: 23rd March 2006, 23:51

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
  •  
Qt is a trademark of The Qt Company.