Answer the question
In order to leave comments, you need to log in
Endless loop in Qthead, how to do it right?
Greetings!
It is required to make an infinite loop to process some data,
the loop is done, it is put into a separate class in the thread, everything works, everything is ok.
But it was necessary to process the signals of the slot, namely, to slow down the cycle, as the slot worked, to continue it. To do this, I already created a bunch of variables for certain slots for each action. In my opinion, the code began to smell of something ...
Maybe there is a "correct" way of doing things in such situations?
As I see it ideally:
in the class, the same function is called instead of the eternal loop, as soon as an event (signal) arrives in the class, it suspends the call and calls the desired slot, as it worked, continues.
Answer the question
In order to leave comments, you need to log in
For a constant loop, you'd be better off implementing a slot that will be constantly called at the end of itself:
test.h:
private slots:
void workMethod();
void Class:workMethod()
{
....
QMetaObject::invokeMethod(this, "workMethod", Qt::QueuedConnection);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question