Local client socket not emitting error when server not running

  • Hi,

    I have a local client socket and it works fine i.e. connects to local (Unix domain) server , receives data.

    But when server is not running it does not emit the error signal, below is the code.


    void ClientThread::serverConnect()
        //Connect to the local notification srever
        socket = new QLocalSocket(this);
        qDebug() << "Client thread: connecting to notification server\n";
        qDebug() << "Client thread: connected to server";
        connect(socket, SIGNAL(readyRead()), this, SLOT(readMsg()), Qt::DirectConnection);   
        connect(socket, SIGNAL(error(QLocalSocket::LocalSocketError)),
                    this, SLOT(displayError(QLocalSocket::LocalSocketError)));
    void ClientThread::displayError(QLocalSocket::LocalSocketError socketError)
        switch (socketError) {
            case QLocalSocket::ServerNotFoundError:
            qDebug() << "Client thread: The host was not found. Please check the "
                        "host name and port settings.";
            case QLocalSocket::ConnectionRefusedError:
                 qDebug() << "Client thread: The connection was refused by the peer. "
                                            "Make sure the fortune server is running, "
                                            "and check that the host name and port "
                                            "settings are correct.";
            case QLocalSocket::PeerClosedError:
             qDebug() << "Client thread: peer closed error.";
               qDebug() << "Client thread: The following error occurred: " << socket->errorString();

  • Qt Champions 2018

    have you tried connecting to the disconnected() signal?

  • Yes , that also does not work, I think disconnected() works when connection is disconnected at run time after successful connection.

  • @nitks.abhinav
    Try to put "connect(socket" lines before this one:


  • Yes it worked, but its strange it should be dynamic. Anyways, Thanks.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.