Important: Please read the Qt Code of Conduct -

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:
    "\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:
    " 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:
    "\u0000Here ist a String\u0000Here ist a String\u0000Something other\u0000"


  • QString escapedString = strPayload_unicode;
    QPlainTextEdit::setPlainText( escapedString);

Log in to reply