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 print unsigned character

How to print unsigned character

Scheduled Pinned Locked Moved General and Desktop
6 Posts 5 Posters 3.7k 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.
  • C Offline
    C Offline
    chandradeo
    wrote on last edited by
    #1

    Hi frnds i get a network packet in which hour,min and second values are sent. The type of these values are indicated as UNSIGNED CHAR. When i read the data in a char array and display it in gui like this

    @ udpSocketRxCDP->readDatagram(buffer, sizeof(buffer));
    ui->textEditsec->setText(buffer[2]); // second @

    it displays some different thing means it is not the second value.

    Can anybody tell me with explanation how should i get the correct value. Thank u all in advance

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      chars, as the name suggests, are treated as characters. So it probably prints a nice letter for you :) Use this instead:
      @
      ui->textEditsec->setText(QString::number(buffer[2]));
      @

      (Z(:^

      1 Reply Last reply
      0
      • C Offline
        C Offline
        chandradeo
        wrote on last edited by
        #3

        [quote author="sierdzio" date="1390394128"]chars, as the name suggests, are treated as characters. So it probably prints a nice letter for you :) Use this instead:
        @
        ui->textEditsec->setText(QString::number(buffer[2]));
        @[/quote]

        Hi sierdzio thank u for ur reply. As i the buffer is a character array QString::number() doesnt takes character array as its argument as i have seen here "Your text to link here...":http://qt-project.org/doc/qt-5/qstring.html#number.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          You can type cast it as a quint8 before converting

          Hope it helps

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • S Offline
            S Offline
            shree_121
            wrote on last edited by
            #5

            @SGaist said in How to print unsigned character:

            type cast it as a quint8

            can you tell me how to type cast unsigned char to quint8?

            aha_1980A 1 Reply Last reply
            0
            • S shree_121

              @SGaist said in How to print unsigned character:

              type cast it as a quint8

              can you tell me how to type cast unsigned char to quint8?

              aha_1980A Offline
              aha_1980A Offline
              aha_1980
              Lifetime Qt Champion
              wrote on last edited by aha_1980
              #6

              @shree_121

              unsigned char c = 0x55;
              
              quint8 q = quint8(c);
              

              But that's very basic C++...

              Qt has to stay free or it will die.

              1 Reply Last reply
              2

              • Login

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