Important: Please read the Qt Code of Conduct -

QProcess fills buffer before emit readyRead()

  • I'm wokring on Linux (Raspbian) with Qt 5.9.2. Using QProcess to ready the output of some Linux commands (i.e. hcitool) leads to waits until the buffer (? about 4k) is filled before catch the readyRead signal in order to read out the data:

    QProcess process;
    connect(&_process, &QProcess::readyRead, this, &Example::process_readyRead);
    process.start("hcitool", QStringList() << "lescan");
    // ...
    void Example::process_readyRead()
        QByteArray line;
        while (!(line = _process.readLine()).isEmpty())
            qDebug() << line;

    I also tried with the Unbuffered option or readAll function, but they don't change the behavior.
    Any idea what's going wrong here?

  • Solved in this way:

    _process.start("stdbuf", QStringList() << "-o" << "0" << "hcitool" << "lescan");

Log in to reply