Hi all,
I'm using Qt 4.7.0 on XP with VS2008.
I want to use QTcpSocket to connect to a server to interchange simple xml telegrams.
Very important is to implement a good reconnect functionality. When I read the docs (examples and forums threads!) I understand the functionality of QTcpSocket is asynchronous which means NO BLOCKING. There are a lot of signals/slots.
Now here the example:
Constructor of mySocket class:
...
m_socket = new QTcpSocket();
connect(m_socket, SIGNAL(readyRead()),
this, SLOT(slotReadData()));
connect(m_socket, SIGNAL(error(QAbstractSocket::SocketError)),
this, SLOT(slotError(QAbstractSocket::SocketError)));
connect(m_socket, SIGNAL(connected()),
this, SLOT(slotConnected()));
connect(m_socket, SIGNAL(disconnected()),
this, SLOT(slotDisconnected()));
...
When I call now m_socket->connectToHost("127.0.0.1", 1234) and there is no socket server running on that port the apps GUI freezes for a short time. And when I call connectToHost(...) inside slotError() and slotDisconnected() the GUI freezes cyclic.
I thought exactly this behaviour is fixed with signals/slots and means asynchronous?
I tried also to put the QTcpClient to a thread's run() method. But I don't know how I can implement a reconnect functionality, reading data, ... and all thread-safe.
Please help me. Thanks a lot.
-jack
Bookmarks