Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QPlainTextEdit should show unicode null character as \u0000 string
Forum Updated to NodeBB v4.3 + New Features

QPlainTextEdit should show unicode null character as \u0000 string

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 892 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MECoder
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by VRonin
      #2
      QString escapedString = strPayload_unicode;
      escapedString.repalce('\0',R"(\u0000)");
      QPlainTextEdit::setPlainText( escapedString);
      

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      4

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved