QT 延时函数

void MainWindow::usleep(unsigned int msec)
{
#if 1  /* 方法1 */
    QElapsedTimer t;

    t.start();
    while (t.elapsed() < msec) {
        QCoreApplication::processEvents();
    }
#endif

#if 1  /* 方法2 */
    QTime dieTime = QTime::currentTime().addMSecs(msec);

    while (QTime::currentTime() < dieTime) {
        QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
    }
#endif
}

你可能感兴趣的:(C/C++,Linux/Linux,C)