It seems QRunnable
does not have a sleep
method.
How can I call method like QThread::sleep
in a QRunnable
?
Don't use platform specific functions. The great advantage of Qt is that it is pretty easy portable. Don't ruin it just with sleep
You, can use QThread::sleep
from QRunnable
or QtConcurent
only in Qt 5, as it is declared public there:
void QThread::sleep ( unsigned long secs ) [static protected] // Qt 4.8
void QThread::sleep(unsigned long secs) [static] // Qt 5.0
You can use mutex as workaround for earlier Qt versions:
QMutex m(QMutex::NonRecursive);
m.lock();
m.tryLock(timeout);
Mutex will fail to lock recursively and will wait for timeout.
Just simply use ::sleep()
it isn't in Qt it's a POSIX.1-2001 function.
Also you can try this code, because QThread::sleep()
calls ::Sleep()
class mythreadhelper : public QThread
{
public:
static void mysleep(int ms)
{
return sleep(ms);
}
};
This question was answered at Qt Centre with a response from Nokia Certified Qt Developer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With