RafaelRSE
8th October 2014, 14:11
Hi,
I'm having trouble with QTcpSocket signals. I'm using QTcpSocket::write() to request the server some data and trying to use the signal readyRead() to receive those data, but it doesn't work. I tried to using others signals (just for test) and none of those work.
Here is my code:
In the constructor I have:
buffer = new QBuffer(this);
socket = new QTcpSocket(this);
buffer->open(QIODevice::ReadWrite);
connect(socket, SIGNAL(readyRead()), SLOT(receiveMessage()));
connect(socket, SIGNAL(error(QAbstractSocket::SocketError)),
SLOT(mostrarErro(QAbstractSocket::SocketError)));
The function to connect to the host:
void Client::connectToServer()
{
Settings::ConnectionData p = c->data(); //ConnectionData is a struct to receive the Data from other form and c is the other form class object
socket = p.socket;
port = p.port;
buffer = p.buffer;
if (socket->state() == QAbstractSocket::UnconnectedState) {
socket->connectToHost(setIp(), port);
}
else {
socket->disconnectFromHost();
}
}
I'm sure that the function receiveMessage() is not being called.
I'm having trouble with QTcpSocket signals. I'm using QTcpSocket::write() to request the server some data and trying to use the signal readyRead() to receive those data, but it doesn't work. I tried to using others signals (just for test) and none of those work.
Here is my code:
In the constructor I have:
buffer = new QBuffer(this);
socket = new QTcpSocket(this);
buffer->open(QIODevice::ReadWrite);
connect(socket, SIGNAL(readyRead()), SLOT(receiveMessage()));
connect(socket, SIGNAL(error(QAbstractSocket::SocketError)),
SLOT(mostrarErro(QAbstractSocket::SocketError)));
The function to connect to the host:
void Client::connectToServer()
{
Settings::ConnectionData p = c->data(); //ConnectionData is a struct to receive the Data from other form and c is the other form class object
socket = p.socket;
port = p.port;
buffer = p.buffer;
if (socket->state() == QAbstractSocket::UnconnectedState) {
socket->connectToHost(setIp(), port);
}
else {
socket->disconnectFromHost();
}
}
I'm sure that the function receiveMessage() is not being called.