Asynchronous event with QtConcurrent
-
Hello,
I wanted to run a asynchronous event on my samson app (I wanted to make the molecule vibrate and still be able to use something else).
I did it using QtConcurrent tools, for this I had to change the content of CMakeLists.txt to add QtConcurrent library. It compiles fine but now my app is not visible anymore in SAMSON Debug. Is it because I changed CMakeLists.txt?
Thanks in advance -
Hi Laetitia,
for efficiency reasons, the data graph is not thread-safe, so there might be issues when modifying the document from several distincts threads (e.g. in the history). So, when we want to do this type of things, we use a
QTimer
.For example you declare in a header a
QTimer
:QTimer animationTimer;
and a slot:
public slots: void animate();
and in your source code (for example in the constructor), you connect the timer to a slot that will perform one update of the system:
connect(&animationTimer, SIGNAL(timeout()), this, SLOT(animate())); animationTimer.setSingleShot(false); // make it repetitive
Then, when you want to start the animation you do:
animationTimer.start(20); // every 20 milliseconds
And when you want to stop the animation you do:
animationTimer.stop();
In your
animate()
slot, you perform one step of the vibration. TheQTimer
will intersperse calls to youranimate()
function as regularly as possible, and SAMSON will still be able to process other events (keyboard, mouse, etc.).Hope this helps,
Stephane
-
Hi Stephane,
thanks for your answer, I'll do that then.
Best
Laëtitia