PDA

View Full Version : initialize QStringList with integers



tommy
12th May 2009, 16:28
I'd like to generate a QStringList where every member is a concequtive integer. How do you load integers as QStringList contents?
This won't work:


QStringList mylist;
for(int i=0; i<100; i++)
mylist.append(i);


Thanks

jpn
12th May 2009, 16:30
See QString::number().

aamer4yu
13th May 2009, 06:07
Will this work ?
mylist.append(QString(i)); :confused:

jpujolf
13th May 2009, 06:48
Will this work ?
mylist.append(QString(i)); :confused:

No. It will not work. Because that call will cast the number to QChar and put into the string the char equivalent to the number, not the number in string format.

As JPN said, you have to take a look at QString.number().

i.e :
mylist.append(QString.number(i)); will work.