i invoking QThread with creating object and using MoveToThread function like it suggest
inside the Object i have loop and i need to be able to set sleep for few seconds between iterations ( to update the main GUI ) searching the web got me to this link:
http://www.qtcentre.org/threads/476-where-s-the-sleep%28%29-func
but this not working inside threads , what is the best way to do this ?
问问题
4702 次
2 回答
3
看一下
void msleep ( unsigned long msecs )
void sleep ( unsigned long secs )
void usleep ( unsigned long usecs )
QThread的方法
这些方法都在qt4中受到保护。因此,如果您使用的是 qt4,则需要从 QThread 派生来访问它们。我不确定它们是否在 qt3 中受到保护。
于 2011-06-07T12:39:40.680 回答
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
于 2011-06-07T17:34:01.490 回答