[Qt-interest] The dangers of removePostedEvents?

Mandeep Sandhu mandeepsandhu.chd at gmail.com
Tue Dec 7 06:18:56 CET 2010


On Mon, Dec 6, 2010 at 10:01 PM, Mihail Naydenov <mlists at ymail.com> wrote:
> I am trying to implement cancellation of work sent to a thread using (only)
> signals and slots method. (object movedToThread, slots do work and emit results
> back)
>
> My problem is if I queue many events I have hard time forcing it to handle only
> the last one, discarding all previous.
>
> (Though I already use a cancel flag, I fail to find a way to set and restore it
> the right way, the above to happen. Another issue is that most of the work
> itself is not cancelable, so it mainly handles stuff, like "don't start it" or
> "don't sent the result" )

Would it work if there is a flag in the worker thread, set from the
main GUI thread, which the worker thread checks before emitting the
result. So, if this "discard result" flag is set, you simply don't
emit the result. Something similar is done in the mandlebrot example
(http://doc.qt.nokia.com/latest/threads-mandelbrot.html). The flag can
be unset once when the main thread is ready to accept the results.

HTH,
-mandeep



More information about the Qt-interest-old mailing list