How do I create a pause/wait function using Qt?

后端 未结 12 2176
执笔经年
执笔经年 2020-11-27 15:19

I\'m playing around with Qt, and I want to create a simple pause between two commands. However it won\'t seem to let me use Sleep(int mili);, and I can\'t find

12条回答
  •  遥遥无期
    2020-11-27 16:02

    Similar to some answers here, but maybe a little more lightweight

    void MyClass::sleepFor(qint64 milliseconds){
        qint64 timeToExitFunction = QDateTime::currentMSecsSinceEpoch()+milliseconds;
        while(timeToExitFunction>QDateTime::currentMSecsSinceEpoch()){
            QApplication::processEvents(QEventLoop::AllEvents, 100);
        }
    }
    

提交回复
热议问题