Results 1 to 8 of 8

Thread: does main thread has sleep() ?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #8
    Join Date
    Oct 2009
    Location
    Germany
    Posts
    120
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: does main thread has sleep() ?

    Sorry but can I use threadsleeper::msleep(m_sleep); to sleep main thread ?
    You can use it to sleep any thread. More precisely, it sleeps the thread that calls this method. And as the main thread is a thread as any other thread, why shouldn't it be sent to sleep by calling this method? If you don't believe, just try this little code snippet:
    Qt Code:
    1. #include <QCoreApplication>
    2. #include <QThread>
    3. #include <iostream>
    4. #include <QTime>
    5.  
    6. class ThreadSleeper:public QThread
    7. {
    8. private:
    9. ThreadSleeper(){};
    10. virtual ~ThreadSleeper(){};
    11.  
    12. public:
    13. using QThread::msleep;
    14. };
    15.  
    16.  
    17. int main(int , char *[])
    18. {
    19. std::cout << "sleeping for 5s" << std::endl;
    20. QTime t;
    21. t.start();
    22. ThreadSleeper::msleep(5000);
    23. std::cout << "slept for " << t.elapsed() << "ms" << std::endl;
    24. }
    To copy to clipboard, switch view to plain text mode 
    Best regards
    ars

    @Prasad_N: I didn't see your previous reply before posting the above.

  2. The following user says thank you to ars for this useful post:

    prasad_N (11th October 2015)

Similar Threads

  1. Replies: 1
    Last Post: 28th March 2012, 18:58
  2. Replies: 5
    Last Post: 22nd February 2011, 21:21
  3. Replies: 9
    Last Post: 28th November 2009, 20:31
  4. Replies: 16
    Last Post: 7th October 2009, 08:17
  5. Main thread - worker thread communication.
    By kikapu in forum Newbie
    Replies: 25
    Last Post: 23rd May 2007, 22: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
  •  
Qt is a trademark of The Qt Company.