How to print unsigned character



  • 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


  • Moderators

    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 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.


  • Lifetime Qt Champion

    Hi,

    You can type cast it as a quint8 before converting

    Hope it helps


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.