Qt debugging error: “while parsing target library

2019-06-13 14:41发布

问题:

I am debugging an application developed in Qt/C++ using QtCreator. My application reads from the serial port using QextSerialPort, where the serial port is connected to a Rhino Mark IV controller.

int  bytesRead;
char buffer[BUFFER_SIZE];
if (_serialPort->bytesAvailable() > 0
    && (bytesRead = _serialPort->read(buffer, BUFFER_SIZE)) > 0)
{
    _comBuffer.append(buffer, bytesRead);
    buffer[bytesRead+1] = 0; // for debugging purposes
    qDebug(buffer);          // for debugging purposes
}

I am having trouble with this, because I try to read some ASCII data, but what I get into the buffer are some strange characters. For example, the ASCII code for number zero ('0') is replaced by another code that is shown by the debugger and printed by qDebug as '°'.

In addition, I get following message in the Application Output tab: while parsing target library list: not well-formed (invalid token).

I wonder why I do not get the appropriate ASCII code with QextSerialPort. Is it a problem of QextSerialPort or of the Rhino Mark IV controller? I am viewing the traffic through the serial port on two monitors, and the ASCII characters are displayed correctly on the monitors. Thus, I have concluded that it is not a problema of the controller or the communication channel.

What does the message while parsing target library list: not well-formed (invalid token) mean and why is it caused?

回答1:

Did you configure the serial port correctly in your application (i.e. baudrate, stop bits, etc.)?

Also, you should not add 1 to bytesRead when zero terminating the buffer as that allows a single unwanted byte at the end of the string.

That error message is generated by gdb, not Qt. It may be related to using files/folders with non-latin1 encoded names.