PDA

View Full Version : QTextStream and hex data



enno
6th April 2015, 16:30
I want to read hex data from a QTextStream


#include <QTextStream>
int main(int, char**) {
QString string("hexvalue 7C00 15");
QTextStream in(&string);
in.setIntegerBase(16);
QString str1, str2;
unsigned int val1;
in >> str1 >> val1 >> str2;
qDebug("%s %x %s", qPrintable(str1), val1, qPrintable(str2));
return 0;
}

This program outputs

hexvalue 0 C00
I thought that setIntegerBase(16) tells the stream to expect hex input when reading integers. The read stops on the character C, whic becomes p[art of a following string.

Can I read a hex value without reading a string and then converting and without a 0x prefix ?
All ideas welcome

Enno

Santosh Reddy
23rd April 2015, 01:41
Don't think there is any other way than reading as string and then to number.