[Development] Evolving Qt's multithreading API

Olivier Goffart olivier at woboq.com
Wed Feb 27 10:53:11 CET 2013


On Wednesday 27 February 2013 11:13:35 Joseph Crowell wrote:
> I have threads that live for the full life of my application but telling
> them to stop on application shut down is painful. For this reason I
> would like to be able to cancel a thread and also have a virtual
> function to handle what happens when tread cancel is requested.. i.e.
> cleanly closing child objects and handling locked mutexes so I don't get
> segfaults. This is possible with current QThread but could be much easier.

You could use the QThread's destructor for that.

MyThread::~MyThread() {
	setShouldExit(true);
	wait();
}


I don't know why we don't call {quit();wait();}  in the default QThread 
destructor instead of calling it undefined behaviour to destroy a running 
thread.  Possibly because it is already too late, and the derived class has 
already been destroyed.
But maybe we still could do it now.

-- 
Olivier 

Woboq - Qt services and support - http://woboq.com - http://code.woboq.org




More information about the Development mailing list