As far as I understand you need to make sure that window is grabbed in the main thread. So the clean way to do it - do it in the main threat without changing affinity . and wait until picture is taken in the threat you need a picture at.
This will also remove race conditions you are facing - your grabWindow might be called from different threads and more of that it might be called at the same time as painting occur, which should not happen. You can't avoid synchronization here. It is your choice through events. mutexes or signal/slots . I would personally prefer last with BlockingQueuedConnection. Regards, Alex On Wed, Aug 7, 2013 at 3:11 PM, Alexander Syvak <alexander....@gmail.com>wrote: > Hello, > > there's a need for each thread to make screenshots and to compare them > with loaded picture using QImage. > Since there's only on GUI thread, I moved the the thread context to the > main thread to make the screenshot in there. > > Here's the code snipper from the worker-threads: > > QPixmap screenshot; > > try > > { > > auto const this_thread = this->thread(); > > moveToThread(QApplication::instance()->thread()); > > screenshot = QPixmap::grabWindow( QApplication::desktop()->winId() ); > > moveToThread(this_thread); > > screenshots.append(screenshot); > > // Compare it with the trigger if there was no match before. > > if ( !matched && event_p && event_p->get_trigger_path().size() && > images_comparator::cmp( screenshot.toImage(), QImage( > event_p->get_trigger_path() ), pattern() ) ) > > { > > qDebug() << "!!! matched !!!"; > > matched = true; > > > However, the grabWindow returns null QPixmap always. > > Who knows how to achive what's needed here? > > _______________________________________________ > Interest mailing list > Interest@qt-project.org > http://lists.qt-project.org/mailman/listinfo/interest > >
_______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest