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

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

    To use the standard sleep function add the following in your .cpp file:

    #include 
    

    As of Qt version 4.8, the following sleep functions are available:

    void QThread::msleep(unsigned long msecs)
    void QThread::sleep(unsigned long secs)
    void QThread::usleep(unsigned long usecs)
    

    To use them, simply add the following in your .cpp file:

    #include 
    

    Reference: QThread (via Qt documentation): http://doc.qt.io/qt-4.8/qthread.html

    Otherwise, perform these steps...

    Modify the project file as follows:

    CONFIG += qtestlib
    

    Note that in newer versions of Qt you will get the following error:

    Project WARNING: CONFIG+=qtestlib is deprecated. Use QT+=testlib instead.
    

    ... so, instead modify the project file as follows:

    QT += testlib
    

    Then, in your .cpp file, be sure to add the following:

    #include 
    

    And then use one of the sleep functions like so:

    usleep(100);
    

提交回复
热议问题