[Interest] QTcpSocket from QTcpServer

Lucas.Betschart at crypto.ch Lucas.Betschart at crypto.ch
Mon Jul 16 13:23:01 CEST 2012


I got a thread access problem with QTcpSocket.

In the initialisation of my object I got 2 QTcpServer created listening on 2 different ports.
For each of them I got a the signal newConnection() linked to a different slot. In each I save the QTcpSocket I get from nextPendingConnection().

Now I got a public slot (slot $A) that gets called from out side my class. In this slot I cast another (of my) slots (slot $B) which writes to one of the QTcpSocket. After that I write to the other QTcpSocket in the slot $A.
When I try to write to slot $A the data doesn't get written and I get the following error:

QObject: Cannot create children for a parent that is in a different thread.
(Parent is QNativeSocketEngine(0x492cd0), parent's thread is QThread(0x3e9db8), current thread is QThread(0x40b8e0)
QSocketNotifier: Can only be used with threads started with QThread

Creating a QTcpSocket by my self in the newConnection Slot and writing to it works.

The QTcpServer documentation says:
Note: The returned QTcpSocket object cannot be used from another thread. If you want to use an incoming connection from another thread, you need to override incomingConnection().

But why does it work in one (slot $B) of them but not in the other (slot $A) ?



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20120716/b8f684f0/attachment.html>

More information about the Interest mailing list