c++ - Update QT Graphicview from other Thread -


I'm really confused about threading in QT. I have read so many different opinions about which I can feel this.

I have a class (computations) that makes heavy computation and produces many solutions. When the solution of this class I

  boost :: function & lt; Zero (Solution) & gt; F;  

A custom function that can be binded with

  f = boost :: bind (& MainWindow :: FoundSolution, this, _1);  

No, I have my main window in quality where I call the computations of my class with

  computation vibration (F); QFuture & LT; Zero & gt; Future = QTConnectant :: Run (Comp, and Computation :: DOSMethink);  

So it calculates when I can use the GUI and I get a response to the new solutions foundsolution function in my main window. In this function I use QGraphicview to get my own solution. Qgraphicsview is a member of my main window.

It sometimes works.

But I often get the following error

Failure failure in QCOREApplication: SendEvent: "Objects can not send aggents to any other thread. Current thread 438 BC 40 Was created in Thread 15dcc00, File Kernel \ qcoreapllication line 494

means I call my GUI application with a thread which is not main and It is prohibited by QT, but it is my promotion Well I should be your main thread or? And why does this sometimes work?

Do you know a better implementation for this? I'm really new with QT and thread.

Thank you for your help.

If you emit a signal from the worker thread, which is linked to the slot of an object In the ui thread, the slot will be executed in the ui thread.

So basically if you want to make a new point in QGraphicsView, draw a signal from your worker thread that passes in the coordinates of the new point to draw. The signal should be linked to something that is in the UI thread. The slot will again draw a new point in the QGraphicsView which will work since the slot execution in the YTi thread.

For more information


Comments