Re: QSocketNotifier: socket notifiers cannot be disabled from another thread
Originally Posted by danadam
If it is a code, why don't you use [code] tag?
I assume that Client class is derived from QThread class.Parent object (Client) was probably created in the main thread. Everything that is done in its run() method is executed in another thread. So child object (QTcpSocket) is created in different thread than its parent lives. This is not allowed and that's why you get error:
yes that is true , but where should I create QTcpSocket, in the constructor of the Client or elsewhere. Also in QT documentation it is stated that
"The child of a QObject must always be created in the thread where the parent was created. This implies, among other things, that you should never pass the QThread object (this) as the parent of an object created in the thread (since the QThread object itself was created in another thread).
"
is this means that child of a QObject(tcpSocket) should be created in the main thread. Or do not passing "this"(Client) into constructor of the tcpSocket in the run method will be sufficent
Hm... I'll be guessing here. Your client thread doesn't have an event loop (you're not calling exec() method anywhere in run()). You are waiting for readyRead in client thread, so in fact you are waiting for some signal from QTcpSocket. But it's impossible to receive it in client thread cause it has no event loop.
Why do I need an evet loop. tcpSocket can signal events such as "connected","disconnected" ,"errors". I do not need to call exec. I will try it.
Problem occurs when Client receives "sendMessage" signal of the sender, and tries to write socket.
Bookmarks