[Interest] how to block run function of QRunnable class

K. Frank kfrank29.c at gmail.com
Tue Mar 19 15:38:21 CET 2013


Hi Frank!

On Tue, Mar 19, 2013 at 10:24 AM, Frank Hemer <frank at hemer.org> wrote:
 On Tuesday 19 March 2013 15:11:03 André Somers wrote:
>> Op 19-3-2013 14:57, K. Frank schreef:
>> > ...
>> > A cross-platform sleep (in a cross-platform framework, at that).  What's
>> > not to like?
>> >
>> > But seriously, does anyone know what the motivation for making sleep
>> > protected might have been?
>>
>> I'm not sure, probably to discourage its usage. Anyway, in Qt 5, there
>> now are static public member functions sleep and usleep in QThread.
>
> Sleep being public tends to make users think it could be called from anywhere
> (not only from within the thread) which might have sideeffects. Thus,
> overwriting QThread implies you're doing sth. non standard and you know what
> you are doing.

I don't really follow the thinking here.

On both windows and linux I can call the native sleep.  I can call it
from the single main thread of a single-threaded program, from a
QThread, from a pthread, from a windows thread, from a std::thread,
and all it does is pause the thread of execution from which it's called.
I don't see anything I would call side effects.

I would think that Qt's sleep should be just a cross-platform wrapper /
normalizer for the native calls.  (I also don't see why sleep should be
a static member of QThread, rather than a free function, other than
maybe a java-esque desire to use classes rather than namespaces.)

No matter.  Tony's hack works for Qt 4, and sleep is public in Qt 5.
I'm just curious -- sometimes there's a method to the madness ...

> Frank


Thanks for the explanation.


K. Frank



More information about the Interest mailing list