Important: Please read the Qt Code of Conduct -

QSerialPort: call waitForReadyRead() in a slot connected to readyRead

  • Hello,
    I do not fully understand if this is legitimate but I use consecutively write, waitForBytesWritten and particularly waitForReadyRead in a slot connected to the signal readyRead().

    The QIODevice::waitForReadyRead() description seems to indicate this is legitimate since
    "readyRead() is not emitted recursively; if you reenter the event loop or call waitForReadyRead() inside a slot connected to the readyRead() signal, the signal will not be reemitted (although waitForReadyRead() may still return true)."

    But the description of QSerialPort::waitForReadyRead seems to contradict the previous description:
    "The function returns true if the readyRead() signal is emitted and there is new data available for reading; otherwise it returns false (if an error occurred or the operation timed out)."

    In my case, this does not work, ie waitForReadyRead returns a timeout error, when the signal and the slot are connected in DirectConnection, but works if they are explicitly connected in QueueConnection.


  • Qt Champions 2020

    1. This "contradict" description also is and for the QAbstractSocket. In principle, nobody understands as it there has to be, since everywhere a behavior is different.

    2. Just do not use waitForXX() inside of slot to avoid of some problems.

Log in to reply