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

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

    This previous question mentions using qSleep() which is in the QtTest module. To avoid the overhead linking in the QtTest module, looking at the source for that function you could just make your own copy and call it. It uses defines to call either Windows Sleep() or Linux nanosleep().

    #ifdef Q_OS_WIN
    #include  // for Sleep
    #endif
    void QTest::qSleep(int ms)
    {
        QTEST_ASSERT(ms > 0);
    
    #ifdef Q_OS_WIN
        Sleep(uint(ms));
    #else
        struct timespec ts = { ms / 1000, (ms % 1000) * 1000 * 1000 };
        nanosleep(&ts, NULL);
    #endif
    }
    

提交回复
热议问题