[Qt-interest] QTexstStream to int and double

Chris chris at flamengro.co.za
Thu Mar 19 09:22:56 CET 2009


Hi All

I have read in the manual

By default, when reading numbers from a stream of text, 
QTextStream will automatically detect the number's base 
representation. For example, if the number starts with "0x", 
it is assumed to be in hexadecimal form. If it starts with 
the digits 1-9, it is assumed to be in decimal form, and so 
on. You can set the integer base, thereby disabling the 
automatic detection, by calling setIntegerBase(). Example:

QTextStream in("0x50 0x20");
int firstNumber, secondNumber;
in >> firstNumber;             // firstNumber == 80
in >> dec >> secondNumber;     // secondNumber == 0
char ch;
in >> ch;                      // ch == 'x'

I read a string from a file ex.

1 2 3 4.5 5.5 6.6

and would like to put it in three different ints and doubles
This is what I tried.

int one, two, three;
double oned, twod threed;
QTextStream ssFile, line;
ssFile.setDevice(&file);
QString stringFile = ssFile.readLine();
line.setString(&stringFile);
line >> one >> two >> three >> oned >> twod >>threed;

but it doesn't work. Is it possible to do something similar
-- 
Chris du Preez

Flamengro

Office  : +27 12 4282989
Fax     : +27 12 4282061
Cell    : +27 83 6337420




More information about the Qt-interest-old mailing list