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.
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.
Well, if they are in standard C++, then they obviously have to be usable in Qt applications, no?
Cheers,
_
, Like it, is it possible with QThread? for example: QThread::sleep(unsigned int)
Last edited by rezas1000; 26th September 2014 at 18:20.
Is there anything you actually do yourself?
Like checking the documentation, or $DEITY forbid, actually trying it?
Cheers,
_
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.
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.
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.
anda_skoa (27th September 2014)
Blocking delay:
Qt Code:
void ClassA::msleep(int msec) { }To copy to clipboard, switch view to plain text mode
Non-blocking delay:
Qt Code:
void ClassA::msleep(int msec) { QEventLoop loop; loop.exec(); }To copy to clipboard, switch view to plain text mode
Bookmarks