[Interest] QThread and QPixmap::grabWindow()
Rainer Wiesenfarth
Rainer_Wiesenfarth at trimble.com
Thu Aug 8 07:34:08 CEST 2013
Am 08.08.2013 00:11, schrieb Alexander Syvak:
> [...]
> auto const this_thread = this->thread ();
> moveToThread (QApplication::instance()->thread());
> screenshot = QPixmap::grabWindow( QApplication::desktop()->winId() );
> moveToThread(this_thread);
> [...]
I think you might have a problem in understanding threads and the thread
context as used in Qt. moveToThread() does NOT change the thread the
current code runs in! It only changes the target for events sent to this
object.
In your example, the thread that executes this->thread() is identical to
the one that executes QPixmap::grabWindow().
You will have to implement synchronization between the main (GUI) thread
and your workers. The workers send an event to the main thread each time
they need a screenshot, the main thread picks up the event, takes the
screenshot and sends an event back to the "caller". The addressed worker
thread then picks up this event and processes the screenshot.
If you have only one worker, you might wrap up your processing in a
single method and use QtConcurrent::run().
Best Regards / Mit freundlichen Grüßen
Rainer Wiesenfarth
--
Software Engineer | Trimble Imaging Division
Rotebühlstraße 81 | 70178 Stuttgart | Germany
Office +49 711 22881 0 | Fax +49 711 22881 11
http://www.trimble.com/imaging/ | http://www.inpho.de/
Trimble Germany GmbH, Am Prime Parc 11, 65479 Raunheim
Eingetragen beim Amtsgericht Darmstadt unter HRB 83893,
Geschäftsführer: Dr. Frank Heimberg, Hans-Jürgen Gebauer
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4495 bytes
Desc: S/MIME Kryptografische Unterschrift
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20130808/5b137868/attachment.bin>
More information about the Interest
mailing list