Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

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

    General and Desktop
    debug window hex qbytearray
    3
    3
    1656
    Loading More Posts
    • 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.
    • kahlenberg
      kahlenberg last edited by

      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 Reply Quote 0
      • McLion
        McLion last edited by

        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 Reply Quote 0
        • T
          t3685 @kahlenberg last edited by

          @kahlenberg

          Would this be of any use:

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

          1 Reply Last reply Reply Quote 0
          • First post
            Last post