[Qt-interest] QRunnable question

Philippe philwave at gmail.com
Tue May 4 15:33:42 CEST 2010


 Em Terça-feira 04 Maio 2010, às 12:43:23, Philippe escreveu:
> > This should work.
> > 
> > Note: because of an API design flaw that Nokia does not want to admit, you
> > won't be able to sleep in your QRunnable code, by using
> > QThread::sleep(...) since this API is "Static protected". Or you have to
> > trick the API.
> 
> We don't admit because we don't consider it a flaw.
> 
> If you're using Concurrent and runnables, you're sending jobs (the runnables) 
> into a shared resource (the thread pool). Those jobs are expected to finish as 
> fast as possible, which would preclude sleeping.
> 
> If you need to sleep, for whatever reason (and the only valid reason I've ever 
> heard is polling hardware), you probably want a long-lived, dedicated thread. 
> So not a thread pool.

These are good arguments for QRunnable, indeed.

But IMHO, not in "practical life". For instance, browsing the
Qt source code reveals a few places where sleep is used in code not
derived from QThread (QProcess, QAudioInputPrivate, QLocalSocket, QSQLite2ResultPrivate...)

In the diversity of user source codes, you can expect other cases.

Philippe





More information about the Qt-interest-old mailing list