Nominate our 2022 Qt Champions!

[SOLVED] QTcpSocket signals problem

  • 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);

    connect(socket, SIGNAL(readyRead()), SLOT(receiveMessage()));
    connect(socket, SIGNAL(error(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 {


    I'm sure that the function receiveMessage() is not being called.

  • I just realized that I was connecting my socket with another socket (p.sockets).

Log in to reply