QPlainTextEdit should show unicode null character as \u0000 string



  • Hi,
    i'm using QPlainTextEdit as text output of incoming messages. The messages is a QByteArray called payload.
    I convert these QByteArrray to Unicode using QTextCodec.

    QByteArray payload; //comes from UDP Socket
    QTextCodec *textCodec = QTextCodec::codecForLocale();
    QString strPayload_unicode = textCodec->toUnicode( payload );
    qDebug() << strPayload_unicode;
    

    The QDebug output of strPayload_unicode is:
    "192.168.001.128\u0000Here ist a String\u0000Here ist a String\u0000Something other\u0000"

    When i use QPlainTextEdit::setPlainText( strPayload_unicode ) to show it in QPlainTextEdit widget the result is:
    "192.168.001.128Here ist a StringHere ist a StringSomething other"

    How can I show the null characters in QPlainTextEdit as String "\u0000"? I want to see in QPlainTextEdit this:
    "192.168.001.128\u0000Here ist a String\u0000Here ist a String\u0000Something other\u0000"

    Greetings
    Stefan



  • QString escapedString = strPayload_unicode;
    escapedString.repalce('\0',R"(\u0000)");
    QPlainTextEdit::setPlainText( escapedString);
    

Log in to reply
 

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