How do I create a pause/wait function using Qt?
From Qt5 onwards we can also use
Static Public Members of QThread
void msleep(unsigned long msecs)
void sleep(unsigned long secs)
void usleep(unsigned long usecs)
I wrote a super simple delay function for an application I developed in Qt.
I would advise you to use this code rather than the sleep function as it won't let your GUI freeze.
Here is the code:
void delay()
{
QTime dieTime= QTime::currentTime().addSecs(1);
while (QTime::currentTime() < dieTime)
QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
}
To delay an event by n seconds - use addSecs(n)
.