PDA

View Full Version : How to "sleep" inside QRunnable-derived class?



TorAn
19th November 2009, 16:12
In my QRunnable-derived class I need to "sleep" until external database operation is completed. How can I do that? QThread::sleep is protected static...

Thanks.

wysota
19th November 2009, 16:17
But ::sleep() isn't.

TorAn
19th November 2009, 16:54
Strange, I can't find this global function in Qt docs or in QThread class. Can you post the link to the doc or let me know where to look for ::sleep()?

wysota
19th November 2009, 17:32
It's not a Qt function. It's a POSIX.1-2001 function. I'm sure Windows has its own equivalent if it doesn't support it directly.

TorAn
19th November 2009, 18:09
I am surprised the there is no qt-way of doing it in platform-independent manner.
Will this hack work?


class mythreadhelper : public QThread
{
public:
static void mysleep(int ms)
{
return sleep(ms);
}
};

squidge
19th November 2009, 21:12
Considering QThread::sleep() calls ::Sleep, I'd have to say yes.

wysota
19th November 2009, 23:03
Will this hack work?

It would be much easier if you just called ::Sleep() or ::sleep(). Or better yet if you used a wait condition.