[Development] QThread usage/guidance
Olivier Goffart
olivier at woboq.com
Fri Oct 5 18:10:39 CEST 2012
On Friday 05 October 2012 15:24:40 Tony Van Eerd wrote:
> So that is the 'recommended' style then?
Depends what you want to do.
If your task is CPU bounded, you can use QtConcurrent.
If you don't need to event loop, you can reimplement the run() function.
I'd use this appreach only if your task make use of the eventloop. For
example if your worker receive "jobs" from signals from the main thread.
But if you only have one process() slot that is trigerred only by the started
signal, it is a bit overkill.
This mailing list is not really for question on how to use Qt. You should use
the interest mailing-list or the forums instead.
--
Olivier
Woboq - Qt services and support - http://woboq.com
>
>
>
> > -----Original Message-----
> > From: Olivier Goffart [mailto:olivier at woboq.com]
> > Sent: Friday, October 05, 2012 10:54 AM
> > To: development at qt-project.org
> > Cc: Tony Van Eerd
> > Subject: Re: [Development] QThread usage/guidance
> >
> > On Friday 05 October 2012 14:31:51 Tony Van Eerd wrote:
> >
> > > What was the final resolution (if any) of the email thread
> > > "QThread::finished() race → fixing QThread"
> > > http://lists.qt-project.org/pipermail/development/2011-
> >
> > November/000284.html
> >
> > >
> > >
> > >
> > > In particular as seen in
> > > http://mayaposch.wordpress.com/2011/11/01/how-to-really-truly-use-
> >
> > qthreads-
> >
> > > the-full-explanation/
> > >
> > >
> > >
> > > worker->moveToThread(thread);
> > > connect(worker, SIGNAL(error(QString)), this,
> > >
> > > SLOT(errorString(QString))); connect(thread, SIGNAL(started()),
> >
> > worker,
> >
> > > SLOT(process())); connect(worker, SIGNAL(finished()), thread,
> > > SLOT(quit())); connect(worker, SIGNAL(finished()), worker,
> > > SLOT(deleteLater())); connect(thread, SIGNAL(finished()), thread,
> > > SLOT(deleteLater()));
> > >
> > >
> > >
> > > Is there a race where the worker deleteLater() doesn't happen due to
> >
> > the
> >
> > > thread having already finished?
> >
> >
> > There used to be that race. But since Qt 4.8, the deleteLater is
> > handled
> > separatly specially to allow this usage (commit 0c643b179)
> >
> > So I see no races.
> >
> > --
> > Olivier
> >
> > Woboq - Qt services and support - http://woboq.com
> >
>
>
>
> ---------------------------------------------------------------------
> This transmission (including any attachments) may contain confidential
> information, privileged material (including material protected by the
> solicitor-client or other applicable privileges), or constitute non-public
> information. Any use of this information by anyone other than the intended
> recipient is prohibited. If you have received this transmission in error,
> please immediately reply to the sender and delete this information from
> your system. Use, dissemination, distribution, or reproduction of this
> transmission by unintended recipients is not authorized and may be
> unlawful.
More information about the Development
mailing list