PDA

View Full Version : qDebug donsn't display 0x00



SwanseaLover
20th April 2013, 06:50
hi every body
my problem in displaying array of hex, the qDebug displays only first 5 characters and treated the sixth charterer as null and it doesn't display the rest.how can i display full array ???
quint64 index =0;
char CMD[100];
CMD[index++]=0x57;
CMD[index++]=0x58;
CMD[index++]=0x10;
CMD[index++]=0x11;
CMD[index++]=0x21;
CMD[index++]=0x00;
CMD[index++]=0x00;
CMD[index++]=0x00;
CMD[index++]=0x00;
CMD[index++]=0x00;
CMD[index++]=0x00;
CMD[index++]=0x00;
CMD[index++]=0x00;
qDebug()<<"CMD"<<(QString::fromStdString(CMD).toAscii().toHex());

output is only:
"5758101121"

Santosh Reddy
20th April 2013, 18:10
Do not convert to QString, instead directly convert to QByteArray.

qDebug() << "CMD" << QByteArray(CMD, index).toHex();

SwanseaLover
21st April 2013, 07:06
thanks very much

what about displaying CMD hex values in LineEdit ,which accept string valuses

for example
ui->Label->setText(QString::fromStdString(CMD).toAscii().toHe x);

i don't want to convert hex valuse of CMD toHex();

sorry i want convert the hex values to Ascii

ChrisW67
22nd April 2013, 01:00
CMD does not contain anything in hex, it's a bucket of bytes stored in an array. If you have a bucket-o-bytes and you want to display that as a string of human-readable numbers in hex then you must, by definition, convert the bytes in some way. If you try to treat the bucket-o-bytes as a standard C-string, i.e. toAscii(), then it will be terminated by the first NUL byte (http://en.wikipedia.org/wiki/Null_character): so don't do that. Santosh Reddy has already told you how to achieve this conversion using QByteArray, and all you have to do is look at the constructors of QString to finish the job.

SwanseaLover
22nd April 2013, 06:32
yes i got it in qdebug
but my problem is display the CMD in setText()

say in case conversion CMD to QbyteArray .how can display the QbyteArray as hex display in setText();??ui->Label->setText(Qstring:: ????(Command));

Added after 30 minutes:

i solved it

QByteArray Command(CMD,index);
QString Result=Command.toHex();
ui->Label->setText(Result);

it works fine...
Many thanks Santosh Reddy & ChrisW67