[Qt-interest] Fwd: ASSERT failure in QMutex::unlock(): "A mutex must be unlocked in the same thread that locked it."

Sean Harmer sean.harmer at maps-technology.com
Sat Jul 17 11:16:21 CEST 2010


On Saturday 17 July 2010 04:39:45 Oluwafemi Ade wrote:
> > In summary, it is best to consider QThread purely as a means of
> > launching another thread, not as the object that does any real work in
> > that thread (unless you do not need the worker thread to be event driven
> > of course as illustrated in the Mandelbrot example). Much better to
> > create QObjects within the worker thread to do the work instead.
> > 
> > HTH,
> > 
> > Sean
> 
>    Hi.......clear explanation. I have a similar issue, the QThread lives in
> the main thread, it was created there, so we create a QObject subclass in
> run and make connections with the QThread subclass and call exec() to make
> the worker event driven.  In my case I want the worker to help send a
> QByteArray to some server, hence I pass a QByteArray, a QTcpSocket, (a
> QObject = 0 as its parent in its .h file) to the worker's constructor in
> run(),

Where do you create the QTcpSocket? The QTcpSocket must have affinity with 
your worker thread for it to work properly. So you should either create it in 
your thread's run function or if it has to be created in a different thread 
(e.g. the main thread) then you should call moveToThread() on it to move it 
over to your worker thread.

This means that the QTcpSocket object will then use your worker thread's event 
loop.

> which it installs as private variables, also in run() before calling
> exec I call, connectToHost() on the passed socket, so that part of the
> connections made is for the workers sendData() function to be called when
> the socket emits connected(), which actually gets called. But I found out
> that write() on the socket in the workers sendData() is not seen by the
> server, though inComingConnection() was seen on the server which triggered
> the worker's sendData() anyways............is there something missing?

If the above does not help you solve it then can you post some code that show 
what you are doing please?

Good luck,

Sean



More information about the Qt-interest-old mailing list