There is a question about slots and signals in Qt C++ in QTcpServer app. I am not very familiar with slots and signals approach. So ...the issue is slots for client socket on server app is not being invoked at all. I think that I use connect function with wrong parametrs.
class CMyClient {
public:
CMyClient();
QTcpSocket* m_pClientSocket;
MainWindow* m_pWin;
public slots:
void onSocketReadyRead();
void onSocketConnected();
void onSocketDisconnected();
void onSocketDisplayError(QAbstractSocket::SocketError);
I am using connect functions here:
void MainWindow::onNewConnection()
{
CMyClient* pClient = new CMyClient();
// set properties
pClient->m_pClientSocket = m_pServSocket->nextPendingConnection();
pClient->m_pWin = this;
// events from client side on server side
connect(pClient->m_pClientSocket, SIGNAL(readyRead()), SLOT(onSocketReadyRead()));
connect(pClient->m_pClientSocket, SIGNAL(connected()), SLOT(onSocketConnected()));
connect(pClient->m_pClientSocket, SIGNAL(disconnected()), SLOT(onSocketDisconnected()));
connect(pClient->m_pClientSocket, SIGNAL(error(QAbstractSocket::SocketError)), SLOT(onSocketDisplayError(QAbstractSocket::SocketError)));
... But these connect functions do not work properly. Clients are connecting, onNewConnection is invoked but events (slots) from client socket do not emerge (readyRead(), etc). Server are able to send messages to clients. Thanks.
In order to use the signals and slots the class must inherit from
QObject
, in your caseCMyClient
you must change it to something similar to:.*h
.cpp
According to the documentation:
So in your case it is missing to place the receiver object.