How to deal with unkown char array data

  • When reading data into my char buffer 4096 from QTcpSocket, sometimes the data looks like:

    Format 1:
    <\000?\000x\000m\000l\000 \000v\000e\000r\000s\000i\000o\000n\000=\000"\0001\000.\0000\000"\000 \00

    and sometimes the data looks like:

    Format 2:
    <?xml version="1.0" encoding="utf-16"?>\r\n<data version="1.0">\r\n <routing>\r\n

    How can I consistently convert the buffer data into a QString?

    QString myString(buffer); works for Format 2, but not for Format 1 and

    QString myString = QString::fromRawData((char*)buffer, bytesReceived) works for Format 1, but not for Format2.


    1. You need to analyze the incoming data and then select correct QString creation procedure.
    2. A data source server should send some flag to identify what kind of format will be used for next message.

Log in to reply

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