Important: Please read the Qt Code of Conduct -

QLocalSocket waitForReadyRead causes unexpected warning

  • I'm using QLocalSocket to use bidirectional communication with a QLocalServer for IPC. The scheme is simple, the client thread sends a message or request and waits for the server to return result data.

    The client writes to the server successfully with the following code:

    @if (!_socket->isOpen())
    qDebug("(!) Connection closed");

    QByteArray data;
    QDataStream out(&data, QIODevice::ReadWrite);
    // write blocksize at first field
    out << data.size() - sizeof(BLOCKSIZE_T);


    I wait for the server to write a response with

    // wait for response

    @ if (!_socket->waitForReadyRead(5000))
    qDebug("(!) Waiting for command result: Operation timeout.");
    return _E_TIMEOUT;
    QByteArray data = _socket->readAll();

        qDebug("Received response from server, data size=%d bytes.", data.length());
        if (data.length() > 0)
            QDataStream in(&data, QIODevice::ReadOnly);
            return _E_NO_DATA;


    I'm getting the expected response from the server, but in the line:

    if (!_socket->waitForReadyRead(5000))

    i get the following warning dumped at the command line:

    QObject::startTimer: Timers can only be used with threads started with QThread

    Note that the client code is at present, a test suite, that does not create any thread, so assume this is a single-threaded, no-event loop program. I expect the waitForReadyRead method to not care about event loops.

    Should I issue the R/W operations for the socket in a new thread ?

    Thank you very much.

  • Qt Champions 2017

    Is it waiting for 5000 msecs ? If yes don't worry about this warning. Looks like you are doing everything in main thread. This wait may cause you main thread to hang and not show or delay UI. So it is not a good practice to give sleep/wait in main thread. For your program if this is not causing issue don't worry.

Log in to reply