[Qt-interest] emit signal from spawned thread

Guido Seifert wargand at gmx.de
Thu Aug 18 23:52:34 CEST 2011


On Thu, Aug 18, 2011 at 09:44:30PM +0000, Cole, Derek wrote:
> Isnt that saying that I basically have to pass a reference of the QFuture to the method that 
> I would be calling with QtConcurrent run to be able to call the progress functions, 
> which could then be monitored by the QFutureWatcher in the master thread?

No, it isn't.

>> QFuture<T> QtConcurrent::run ( Function function, ... )

>> Runs function in a separate thread. The thread is taken from the
>> global QThreadPool. Note that the function may not run immediately;
>> the function will only be run when a thread is available.

>> T is the same type as the return value of function. Non-void return
>> values can be accessed via the QFuture::result() function.

And especially:
>> Note that the QFuture returned by QtConcurrent::run() does not support
>> canceling, pausing, or progress reporting. The QFuture returned can
>> only be used to query for the running/finished status and the return
>> value of the function.

QtConcurrent::run() executes a _function_. With QFuture/QFutureWatcher
you can receive a signal when the function finishes and get the
result. I don't see a way to get access to the underlying thread object to
make connections. I don't say there is none, but I doubt it. It would
somewhat contradict the purpose of QtConcurrent:run. 

Guido

> 
> ________________________________________
> From: qt-interest-bounces+dcole=integrity-apps.com at qt.nokia.com [qt-interest-bounces+dcole=integrity-apps.com at qt.nokia.com] on behalf of Guido Seifert [wargand at gmx.de]
> Sent: Thursday, August 18, 2011 5:31 PM
> To: TrolltechInterest
> Subject: Re: [Qt-interest] emit signal from spawned thread
> 
> > How can I make this work?
> 
> By reading the documentation of QtConcurrentRun?
> 
> The object, which 'spawns' your thread (actually takes a thread from
> the thread pool) is _not_ the thread object. So connecting signals
> does not make much sense. Regardless where you put your connects.
> 
> >From the docs:
> > To run a function in another thread, use QtConcurrent::run():
> 
> >  extern void aFunction();
> >  QFuture<void> future = QtConcurrent::run(aFunction);
> 
> > This will run aFunction in a separate thread obtained from the default
> > QThreadPool. You can use the QFuture and QFutureWatcher classes to
> > monitor the status of the function.
> 
> I did not look much deeper and might have missed a trick, but I doubt
> you can use QtConcurrentRun the way you want to.
> 
> 
> Guido
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-interest



More information about the Qt-interest-old mailing list