如何使用Qt创建暂停/等待功能? [英] How do I create a pause/wait function using Qt?

查看:1665
本文介绍了如何使用Qt创建暂停/等待功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在玩 Qt ,我想在两个命令之间创建一个简单的暂停。但是,它不会让我使用 Sleep(int mili); ,我找不到任何明显的等待函数。

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 any obvious wait functions.

我基本上只是做一个控制台应用程序来测试一些类代码,稍后将包含在一个合适的Qt GUI,所以现在我不打扰打破整个事件驱动模型。

I am basically just making a console application to test some class code which will later be included in a proper Qt GUI, so for now I'm not bothered about breaking the whole event-driven model.

推荐答案

QtTest中,使用 qSleep()提到使用某个时间暂停 模块。为了避免在 QtTest 模块中的开销链接,查看该函数的源代码,你可以自己复制并调用它。它使用定义来调用Windows Sleep()或Linux nanosleep()

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 <windows.h> // 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
}

这篇关于如何使用Qt创建暂停/等待功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆