iTayb
iTayb

Reputation: 12753

QThread hungs up when calling isRunning on it

I have a QThread that fetches data from the web. Sometimes the user asks for something else, and the data needs to be fetched changes as well.

In my current configuration, I call terminate() upon the thread, change the input data, and call start() on the thread again. Now, that works fine, but sometimes I get the main eventloop stuck when calling isRunning() or isFinished() upon a terminated thread. It gets stuck forever, and does not recover until I kill the process.

  1. Why would isRunning() or isFinished() hung in the first place? They don't suppose to block.
  2. Is this workflow acceptable? If not, how can I stop a thread's process when I don't need it no more (or how can I abandon it)?

Upvotes: 0

Views: 123

Answers (2)

iTayb
iTayb

Reputation: 12753

It seems that in some cases, the thread becomes unusable after termination, and isRunning() and isFinished() may hang the calling thread, even if called only after the TERMINATED signal.

My workaround was to terminate a thread, forget about it and start a new one.

Upvotes: 0

mata
mata

Reputation: 69062

Don't use terminate(), read the warning in the documentation.

Whil it is possible to restart a QThread, restarting threads usually is not a good idea, there should be a better solution to do what you're trying to do.

Upvotes: 1

Related Questions