[Qt-interest] Long Calculations, QThread Event Loop, Signals & Slots
Andre Somers
andre at familiesomers.nl
Mon Jan 17 22:57:48 CET 2011
Hi,
Op Ma, 17 januari, 2011 10:43 pm, schreef Etienne Sandré-Chardonnal:
> There may be an alternative solution :
>
> You still split your processing in slices as in André's example, each
> slice
> being processed by a slot (for example : compute() )
> You create a signal, nextCompute()
> You connect nextCompute to compute using a *queued connection*. (standard
> connection will not work)
> Then, at the end of compute(), you do "emit nextCompute"
>
> In that ways, each computation slice queues the next one when it finishes.
> As this is queued, any slot such as cancel() triggered during the slice
> computation will emit before the next slice is computed.
>
> I've never tried this, so it may be totally stupid. But I did not yet find
> any reason it should be. It seems quite clean.
The approach above works just fine. It is the same approach as the one I
suggested to use with a single shot, 0 ms timer. Using a single shot timer
or a queued method call (you could also use QMetaObject::invokeMethod; no
need for an actual signal emission) does not make much difference. Hence
the "for example" there. I have used both ways, and they both work. So,
IMHO, it is not realy an alternative solution, just a slight variation in
an already proposed solution.
André
More information about the Qt-interest-old
mailing list