Howto know whether the Qthread is running inside an object ?
-
I've implemented my Qthread as fol:
Listening Listen2Clients; // Inherits from QObject QThread *listening_thread = new QThread(); Listen2Clients.moveToThread(listening_thread); QObject::connect(listening_thread, SIGNAL(started()), &Listen2Clients, SLOT(process())); QObject::connect(&Listen2Clients, SIGNAL(finished()), listening_thread, SLOT(quit()));
listening_thread->start();
There is a member function in Listen2Clients class like the following :-
void Listening::recvFromQml(...){ // Here I want to know whether the listening_thread is running or not }
I cannot use "this->isRunning()" in Listening::recvFromQml().
-
What exactly do you want to achieve? Why do you need to know where Listening is running at this place?
-
@Christian-Ehrlicher
Listening::recvFromQml() is connected with a button on the app interface, everytime i press a button, i want the listening_thread to restart.
But before it restarts, i need to know whether that thread is running or not -
@pingal How should this work - Listen2Clients is in the running in this thread so it can't restart it's own thread. What exactly are you trying to solve with this?
-
@pingal said in Howto know whether the Qthread is running inside an object ?:
Listening::recvFromQml() is connected with a button on the app interface, everytime i press a button, i want the listening_thread to restart.
But before it restarts, i need to know whether that thread is running or notDo you mean:
void Listening::recvFromQml(...){ if(this->thread()->isRunning()) { ... } }
EDIT: but this looks to me like a very bad/error prone coding style
-
you ppl are right, i'm doing it in the wrong way, let me clarify my objective.
Listening::recvFromQml(...) receive information from QML and start processing in the listening_thread . I want to restart the whole process when new-information is received (i.e. restart the whole processes (thread) when Listening::recvFromQml(...) is invoked again)
-
Then (stop the old and) create the new thread inside recvFromQml().