我通过创建对象调用QThread并使用它建议的MoveToThread函数
在对象内部我有循环,我需要能够在迭代之间设置睡眠几秒钟(更新主GUI)搜索网络让我到这个链接:
http://www.qtcentre.org/threads/476-where-s-the-sleep%28%29-func
但这不能在线程内部工作,最好的方法是什么?
答案 0 :(得分:3)
看看
void msleep ( unsigned long msecs )
void sleep ( unsigned long secs )
void usleep ( unsigned long usecs )
的方法
这些方法在qt4中都受到保护。因此,如果使用qt4,则需要从QThread派生来访问它们。我不确定他们是否在qt3中受到保护。
答案 1 :(得分:0)
这就是我解决QThread sleep
被保护函数的问题:
// QThread has static sleep functions; but they're protected (duh).
// So we provide wrapper functions:
//
// void MyLib::sleep (unsigned long secs)
// void MyLib::msleep (unsigned long msecs)
// void MyLib::usleep (unsigned long usecs)
#include <QThread>
namespace MyLib
{
class DerivedFromQThread : protected QThread
{
public:
static void sleep (unsigned long secs) { QThread::sleep (secs) ; }
static void msleep (unsigned long msecs) { QThread::msleep (msecs) ; }
static void usleep (unsigned long usecs) { QThread::usleep (usecs) ; }
} ;
void sleep (unsigned long secs) { DerivedFromQThread::sleep (secs) ; }
void msleep (unsigned long msecs) { DerivedFromQThread::msleep (msecs) ; }
void usleep (unsigned long usecs) { DerivedFromQThread::usleep (usecs) ; }
} // namespace MyLib