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. How to display a variable of type QByteArray in Debug Window?
QtWS25 Last Chance

How to display a variable of type QByteArray in Debug Window?

Scheduled Pinned Locked Moved Unsolved General and Desktop
debug windowhexqbytearray
3 Posts 3 Posters 1.9k Views
  • 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.
  • kahlenbergK Offline
    kahlenbergK Offline
    kahlenberg
    wrote on last edited by
    #1

    Hi,
    I want to display a QByteArray variable as 8-bit hex (2 characters) in Debug Window, not with qDebug.
    I am attaching screenshoot for better understanding.
    Thanks.

    Screenshoot
    (I did not find any image embed function in forum, I have uploaded it on postimage.org)

    T 1 Reply Last reply
    0
    • McLionM Offline
      McLionM Offline
      McLion
      wrote on last edited by
      #2

      You may use something like this as a base for your own solution.

      QString toDebug(const QByteArray & line)
      {
        QString s;
        uchar c;
      
        for ( int i=0 ; i < line.size() ; i++ )
        { c = line[i];
          if ( c >= 0x20 and c <= 126 )
            { s.append(c); }
          else
            { s.append(QString("<%1>").arg(c, 2, 16, QChar('0'))); }
        }
        return s;
      }
      
      1 Reply Last reply
      0
      • kahlenbergK kahlenberg

        Hi,
        I want to display a QByteArray variable as 8-bit hex (2 characters) in Debug Window, not with qDebug.
        I am attaching screenshoot for better understanding.
        Thanks.

        Screenshoot
        (I did not find any image embed function in forum, I have uploaded it on postimage.org)

        T Offline
        T Offline
        t3685
        wrote on last edited by
        #3

        @kahlenberg

        Would this be of any use:

        http://doc.qt.io/qt-5/qbytearray.html#toHex

        1 Reply Last reply
        0

        • Login

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