qDebug donsn't display 0x00
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).toAs cii().toHex());
output is only:
"5758101121"
Re: qDebug donsn't display 0x00
Do not convert to QString, instead directly convert to QByteArray.
Code:
qDebug
() <<
"CMD" <<
QByteArray(CMD, index
).
toHex();
Re: qDebug donsn't display 0x00
thanks very much
what about displaying CMD hex values in LineEdit ,which accept string valuses
for example
ui->Label->setText(QString::fromStdString(CMD).toAscii().toH ex);
i don't want to convert hex valuse of CMD toHex();
sorry i want convert the hex values to Ascii
Re: qDebug donsn't display 0x00
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: 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.
Re: qDebug donsn't display 0x00
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