非阻塞延时:
void MyTool::delaymsec(int msec)
{
QTime dieTime = QTime::currentTime().addMSecs(msec);
while (QTime::currentTime() < dieTime)
QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
}
阻塞延时:
void MyTool::delaymsec(int msec)
{
QTime ntime = QTime::currentTime();
QTime ctime;
do {
ctime = QTime::currentTime();
} while (ntime.msecsTo(ctime) <= msec);
}