QByteArray to QString

QByteArray to QString

Asked on January 3, 2019 in Qt.
Add Comment


  • 3 Answer(s)

    QByteArray to QString:

    Click this link to get more information.  QTextCodec 

    QString DataAsString = QTextCodec::codecForMib(1015)->toUnicode(Data);
    

    1015 is UTF-16, 1014 UTF-16LE, 1013 UTF-16BE, 106 UTF-8

           The string “test” is encoded as “t\0 e\0 s\0 t\0 \0 \0” in the encoding and every ascii character is followed by a \0-byte, or  ascii character is encoded as 2 bytes. The only unicode encoding in which ascii letters are encoded in the same way are UTF-16 or UCS-2  which is a  secured version of UTF-16,  in the case of 1015 mib to assume the local input endless.

    Answered on January 3, 2019.
    Add Comment

    The alternative answer is:

    By using the  QString::fromAscii()

    QByteArray data = entity->getData();
    QString s_data = QString::fromAscii(data.data());
    

    The  data() retracting  a char*

    In QT5  use  the CString() alternative as fromAscii()

    Answered on January 3, 2019.
    Add Comment

    The initialize code is:

    QString::fromStdString(byteArray.toStdString())
    
    Answered on January 3, 2019.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.