1. ///
    2. /// \brief MainWindow::sleep make the process wait a period of time
    3. /// \param msec milliseconds num
    4. ///
    5. void MainWindow::sleep(unsigned int msec)
    6. {
    7. QTime reachTime = QTime::currentTime().addMSecs(msec);
    8. while (QTime::currentTime()<reachTime) {
    9. QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
    10. }
    11. }
    • 借用系统时间来判断延时时长是否满足后跳出循环