Results 1 to 8 of 8

Thread: are there functions for delay in Qt?

  1. #1
    Join Date
    Jul 2014
    Posts
    95
    Thanks
    67

    Default are there functions for delay in Qt?

    Hello. in standard c++, there are functions for delay such as delay(int msec).I want to know that are there functions for delay in Qt? thank you.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: are there functions for delay in Qt?

    Well, if they are in standard C++, then they obviously have to be usable in Qt applications, no?

    Cheers,
    _

  3. #3
    Join Date
    Jul 2014
    Posts
    95
    Thanks
    67

    Default Re: are there functions for delay in Qt?

    , Like it, is it possible with QThread? for example: QThread::sleep(unsigned int)
    Last edited by rezas1000; 26th September 2014 at 18:20.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: are there functions for delay in Qt?

    Is there anything you actually do yourself?
    Like checking the documentation, or $DEITY forbid, actually trying it?

    Cheers,
    _

  5. #5
    Join Date
    Jul 2014
    Posts
    95
    Thanks
    67

    Default Re: are there functions for delay in Qt?

    I saw the documentation and In fact, QThread::sleep() or QThread::msleep() are for delay operation.What do you think? if this is wrong please correct.thank you.

  6. #6
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: are there functions for delay in Qt?

    Yes those functions can be used to suspend a thread for a given interval. Why do you need that ?
    Maybe a single shot timer would be better ? Forcing a thread to sleep is rarely needed.

  7. #7
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: are there functions for delay in Qt?

    Anda_skoa is merely expressing that, even though you found these in the docs, you would rather ask this forum to verfy things for you rather than simply trying it yourself. Quite often the question takes longer to type than trying it yourself would have.

    Yes, those functions exist in QThread, and yes they cause blocking delays. Blocking delays are usually not what you want in a Qt program (and they usually lead newbies to think they need threads further confusing the issue). For the usual Qt way of having something happen in x milliseconds see QTimer.

  8. The following user says thank you to ChrisW67 for this useful post:

    anda_skoa (27th September 2014)

  9. #8
    Join Date
    Jun 2010
    Location
    Israel
    Posts
    1
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: are there functions for delay in Qt?

    Blocking delay:

    Qt Code:
    1. void ClassA::msleep(int msec)
    2. {
    3. QThread::msleep(msec);
    4. }
    To copy to clipboard, switch view to plain text mode 

    Non-blocking delay:

    Qt Code:
    1. void ClassA::msleep(int msec)
    2. {
    3. QEventLoop loop;
    4.  
    5. QTimer::singleShot(msec, &loop, &QEventLoop::quit);
    6.  
    7. loop.exec();
    8. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. qt How to set delay?
    By lapdx in forum Qt Programming
    Replies: 1
    Last Post: 9th November 2012, 15:45
  2. Replies: 5
    Last Post: 27th August 2011, 03:09
  3. To add delay
    By vinayaka in forum Newbie
    Replies: 0
    Last Post: 3rd June 2011, 13:21
  4. Add Delay.
    By Johncdy in forum Qt Programming
    Replies: 1
    Last Post: 16th March 2011, 08:18
  5. How can i delay a function?
    By firenet in forum Qt Programming
    Replies: 2
    Last Post: 24th January 2007, 03:58

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.