Could slot function and mouseMoveEvent be possibly excuted concurrently in a muti-cores machine?
-
class MyScene : public QGraphicsScene { ... MyScene() { ... m_mouseEventEnabled = false; thread.start(); connect(&thread, SIGNAL(finished()), this, SLOT(mouseEventEnabledSlot())); ... } ... public slots: void mouseEventEnabledSlot() { m_mouseEventEnabled = true; } protected: void mouseMoveEvent(QGraphicsSceneMouseEvent* event) { if (m_mouseEventEnabled) { do_mouse_move_thing(); } } private: bool m_mouseEventEnabled; MyThread thread; ... }
Just as the code show, when the thread finishes,
m_mouseEventEnabled
will be set totrue
, for variablem_mouseEventEnabled
, this is a writing behavior,but the
m_mouseEventEnabled
in functionmouseMoveEvent
may always do a reading behavior,The program will be run in a muti-cores machine, and what I want to know is that whether the two behaviors can possibly excute concurrently?
( I know little about the underlying implementation mechanism in Qt, but after I google the relevant articles, I think it will never happen, just my plain view).
-
@Limer said in Could slot function and mouseMoveEvent be possibly excuted concurrently in a muti-cores machine?:
What you mean is the two behaviors can be excuted concurrently ?
yes
-
Normally, a widget's slot functions and event functions are run in the GUI thread.
It is possible to run function concurrently from mouseMoveEvent() by running the function in a different thread. However, it is best to implement that function in a different class (unless you really really know what you are doing)