不多说了,直接上代码+注释:
void simpleWait(int msec) { // 时间的精度只有10ms /*QTime dieTime = QTime::currentTime().addMSecs(msec); while (QTime::currentTime() < dieTime) QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);*/ // 比实际多2~3秒 /*QDeadlineTimer timer(msec,Qt::PreciseTimer); while(!timer.hasExpired()) QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);*/ // 这个时间更长 /*QElapsedTimer timer; timer.start(); while(!timer.hasExpired(msec)) QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);*/ // 这个最准 QTimer timer; timer.setTimerType(Qt::PreciseTimer); timer.start(msec); while(timer.remainingTime() > 0) QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents); }