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

后端 未结 12 2178
执笔经年
执笔经年 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:08

    I wrote a super simple delay function for an application I developed in Qt.

    I would advise you to use this code rather than the sleep function as it won't let your GUI freeze.

    Here is the code:

    void delay()
    {
        QTime dieTime= QTime::currentTime().addSecs(1);
        while (QTime::currentTime() < dieTime)
            QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
    }
    

    To delay an event by n seconds - use addSecs(n).

提交回复
热议问题