Reputation: 34760
I just found it is NOT easy to make a sleep call in Qt4. I wrote some code in Qt5 and have few QThread::msleep()
calls in my main()
and other places. I want to convert those code to Qt4 but cannot find an easy way to convert these msleep calls.
error: C2248: 'QThread::msleep' : cannot access protected member declared in class 'QThread'
Somebody suggested subclass the QThread class. Why I need to go that far? no simple way to just sleep a while?
Upvotes: 2
Views: 3192
Reputation: 37697
You can subclass QThread to expose this methods if you insist on sleep:
class SleepThread : public QThread {
public:
static inline void msleep(unsigned long msecs) {
QThread::msleep(msecs);
}
};
Upvotes: 4
Reputation: 575
You can use a wait condition:
QWaitCondition wc;
QMutex mutex;
QMutexLocker locker(&mutex);
wc.wait(&mutex, milliseconds);
Upvotes: 6