Results 1 to 6 of 6

Thread: How to Implement Sleep() or wait() in Qt app

  1. #1
    Join Date
    Jul 2009
    Posts
    36
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default How to Implement Sleep() or wait() in Qt app

    Hi All,

    I want to Implement Sleep() or wait() in Qt.

    I have used QTest::sleep(250); but it not work properly in my application.

    Is there any another option that I can use?

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to Implement Sleep() or wait() in Qt app

    How about ::Sleep(ms) ?

    But what do you mean by "not work properly" ?

  3. #3
    Join Date
    Jul 2009
    Posts
    36
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: How to Implement Sleep() or wait() in Qt app

    Actually I am using Thread and I want to Pause the main application for few sec to receive the data but when I Implement QTest class I got error, It might be possible that I am not implementing properly. Please help me how to use the Sleep() in Qt.

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

    Default Re: How to Implement Sleep() or wait() in Qt app

    Actually I am using Thread and I want to Pause the main application for few sec to receive the data
    I don't know what you design is, but this sounds like trouble.
    You should not make the main GUI thread wait, it also makes no sense, if you are using threads, that is what thread are for - to allow parallel execution.
    If you want the application thread to wait, you actually don't need another thread, just do your task in the main thread, it will then wait for your task to end.
    But note, that as long as the GUI thread waits for your task to finish, the application will be non responsive, since no events will be handled by the application.

    Never the less, QThread has a public wait and protected sleep functions.
    ==========================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.

  5. #5
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to Implement Sleep() or wait() in Qt app

    Quote Originally Posted by sosanjay View Post
    Actually I am using Thread and I want to Pause the main application for few sec to receive the data
    Is there a reason why the thread can not send signal to main application thread to state when the data is ready instead of waiting for it? As high_flyer says, waiting in my thread is very bad. On Windows, this can cause the OS to place the text "Not Responding" on your window, as you will not be replying to messages from the OS.

  6. #6
    Join Date
    Dec 2009
    Location
    Romania, Iasi
    Posts
    18
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to Implement Sleep() or wait() in Qt app

    Read more about QWaitCondition. There is a wait() function that is what you need.

Similar Threads

  1. How do you sleep when using a QTimer
    By newqtuser in forum Qt Programming
    Replies: 0
    Last Post: 30th October 2008, 00:49
  2. Replies: 1
    Last Post: 14th June 2007, 15:52
  3. wait copy picture then show it
    By raphaelf in forum Newbie
    Replies: 6
    Last Post: 5th November 2006, 12:09
  4. QSA scripts: how to wait for events?
    By olberg in forum Qt Programming
    Replies: 2
    Last Post: 17th May 2006, 14:56
  5. sleep - sleeps, but not when I want it to sleep
    By nongentesimus in forum Newbie
    Replies: 2
    Last Post: 2nd March 2006, 14:43

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.