[solved] QtSerialPort - Problem with waitForReadyRead() and bytesAvailable()

  • Hello

    I can't get the functions waitForReadyRead() and bytesAvailable() to work as I expect them to.

    I'm using Qt 4.7.4, Win 7, MinGW compiler.
    QtSerialPort downloaded 11 Feb 2013.

    The code in short is:

        RS232Cmd[0] = 0x1B; // 2 bytes, Esc A
        RS232Cmd[1] = 'A';
        bTest = serial->waitForReadyRead(5000);
        qDebug("w %d", bTest);
        temp_value  = serial->bytesAvailable();
        temp_value2 = serial->read(RS232Buffer, 8);
        qDebug("a %d", temp_value);
        qDebug("r %d", temp_value2);


    The output I get is this:
    w 0
    a 0
    r 0

    First of all, with the 5000 parameter to waitForReadyRead(); I expect the program to wait 5 seconds before displaying the debug output if no data comes in, but there is no wait time that I can notice.

    Second, I can see on the oscilloscope that the two bytes ('Esc' + 'A') are sent and that a 8 byte reply is received within 2ms.

    Third, with a terminal program I can verify that the 8 byte reply is correctly received on the PC.

    Any ideas on what's going wrong?
    Or have I misunderstood the functionality of these functions?

  • Yes, it is a bug. Thx for posting.

    Patch to fix it here: https://codereview.qt-project.org/#change,47729

    You can wait and update repo after applied this patch,
    or make changes yourself.

  • Thanks kuzulis,

    I changed line 161 in qserialport_win.cpp from:
    return error;
    return !error;

    and now my simplified example works.

    Now, I can start working on the more complex software.

  • Please add [SOLVED] to caption

Log in to reply

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