Solved How Connect Two Timed Methods in sequence
-
Hi!
I have a simple doubt here , and i dont know if it´s possible with Qt:I have a simple OpelGL Window where i use a Render method to update the rendering using a timer as below:
connect(this, SIGNAL(widthChanged (int)), this, SLOT(resizeGl())); connect(this, SIGNAL(heightChanged(int)), this, SLOT(resizeGl())); timer = new QTimer(this); connect(timer, SIGNAL(timeout()), this, SLOT(RenderScene())); timer->start(0);
My doubt is:
It´s possible i connect another method like "UpdateScene" slot that be executed only after RenderScene finish it´s job?Any help will be much appreciated becouse i´m having syncronization issues between the rendering being performed in the screen and the data being updated on the aplication, since the GPU´s are rendering in threads.
Kind Regards.
-
Hi @wwolff
I might be missing the point of what you're asking, but as slots are just regular functions, you can always call one from the other, eg:
void MyClass::RenderScene() { // do whatever RenderScene does. UpdateScene(); // invoke the UpdateScene slot directly. }
If you're bothered by the added coupling, you can emit your own signal as a go-between, eg:
void MyClass::MyClas(...) { connect(this, SIGNAL(sceneRendered()), this, SLOT(UpdateScene())); // the rest of your sample code from above here... } void MyClass::RenderScene() { // do whatever RenderScene does. emit sceneRendered(); }
Since you've specifically mentioned using threads, you probably want to use the signal/slot separation, because that allows you to use Qt's queued connections (or other connection types as appropriate) if signalling from one thread, to another's slot... have a read of Signals and Slots Across Threads.
Cheers.
-
Thanks so much!
This is exactly what´s i´m looking for (A way to fire up a signal to inform that my UpdateScene Method need be executed).I will try it!