Solved QTcpServer newConnection signal is not emitted, even after the connected signal is emitted on the clients QTcpSocket
-
Server:
m_server = new QTcpServer(this); connect( m_server, SIGNAL( newConnection() ), this, SLOT( client_connected() ) ); if (m_server->listen(QHostAddress::Any, 55556) == false) { logger.log("Server failed to listen to port 55556"); }
Client:
m_socket = new QTcpSocket(); connect( m_socket, SIGNAL( connected() ), this , SLOT( connected_to_server() ) ); m_socket->connectToHost(address, 55556);
The clients QTcpSocket connected SIGNAL gets emitted and connected_to_server gets called, but on the server side the SIGNAL newConnection does not get emitted!
Port is not used, firewall exception is active on both sides, event loop exists
-
Hi,
Are you running the client and server on the same machine ?
What version of Qt are you using ?
If using Qt 5, you should change your connection statement and use the new style using function pointers, that will give you compile errors in case you have an error in your methods name. -
@SGaist Hi,
I tried it on the same and on different machines.
I use Qt 4.8.2.
Do you mean SLOT( &classname::function_name ) instead of SLOT( function_name() ) ?thanks
-
That's not that. Please read the Signals & Slots chapter of Qt's documentation. However, as already stated, it's only valid for Qt 5.
Before going further, are you locked to that outdated version of Qt ? If so, can you at least update to Qt 4.8.7 which is the latest and last version of the Qt 4 series.
-
@SGaist I think I can update to the newest version without a big problem, so I will try that.
-
Unless you are locked to the Qt 4 series, you should move to Qt 5.12.
-
@SGaist I updated both the client and server project to Qt 5.12 and now it works! Thank you!
-
Good !
Then please mark the thread as solved using the "Topic Tools" button so that other forum users may know a solution has been found :)