[Qt-interest] QThread::sleep static protected

Karol Krizka kkrizka at gmail.com
Sun May 31 14:48:34 CEST 2009


Hi there,

2009/5/31 Patric <userqt at gmail.com>:
> Hello,
> I'm trying to sleep my thread for 5 seconds and I tried to use
> QThread::sleep. But it's protected and it seems I can't use it.
> QThread::sleep(5); for example.
>
A google search turns up this thread:
http://lists.trolltech.com/qt-interest/2007-01/thread00133-0.html

It seems that you will have to implement your own sleep function.
However, there is also an earlier thread:
http://lists.trolltech.com/qt-interest/2005-08/thread00071-0.html
According to it, it is not a good idea to pause an interactive
application like those build with Qt, and I tend to agree with that.
However, that argument does not work with console applications, which
Qt supports. If that is the case, did you think about using the
standard C sleep() function?

> What's the best way to pause my program for 5 seconds, I'm trying to
> implement a timeout.
>
What do you mean you're trying to implement a timeout? Are you trying
to do some task (ei: connect somewhere), and if it does not succeed in
a certain time, then kill it and inform the user? If so, I don't think
pausing the program for 5 seconds is a good idea. What if the task
completes before 5 seconds are up? Plus this will keep your
application in an unresponsive state (including no redraws).

--
Cheers,
Karol Krizka
http://www.krizka.net



More information about the Qt-interest-old mailing list