void QUIHelper::delay(int msec)
{ // 这个最准
/*非阻塞方式延时,现在很多人推荐的方法*/
QEventLoop loop;
QTimer::singleShot(msec, &loop, SLOT(quit()));
loop.exec();
}
void QUIHelper::deferred(int msec)
{ // 这个最准
QTimer timer;
timer.setTimerType(Qt::PreciseTimer);
timer.start(msec);
while(timer.remainingTime() > 0)
QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
}
void QUIHelper::sleep(int msec)
{
//非阻塞方式延时,不会卡住主界面
if (msec <= 0) {
return;
}
//#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
// QThread::msleep(msec);
//#else
QTime endTime = QTime::currentTime().addMSecs(msec);
while (QTime::currentTime() < endTime) {
QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
}
//#endif
}
https://blog.csdn.net/weixin_41882459/article/details/139282904
标签:Qt,int,QTime,msec,timer,QEventLoop,延时,精准 From: https://www.cnblogs.com/xihong2014/p/18220633