回复: Qt程序中用了QTest::qWait(800);//延迟0.8秒,但是运行exe程序会同时弹出一个DOS窗口
#11 [ustone 05-29 13:07]
貌似应该:
#ifdef Q_OS_WIN
Sleep(1);
#else
struct timespec ts = { 0, 1 * 1000 * 1000 };
nanosleep(&ts, NULL);
#12 [ustone 05-29 13:10]
漏了#endif
Qt自定义延时函数:
void Wait(int ms)
{
QElapsedTimer timer;
timer.start();
do {
QCoreApplication::processEvents(QEventLoop::AllEvents, ms);
#ifdef Q_OS_WIN
Sleep(1);
#else
struct timespec ts = { 0, 1 * 1000 * 1000 };
nanosleep(&ts, NULL);
#endif
} while (timer.elapsed() < ms);
}