PDA

View Full Version : QList



eleanor
25th October 2007, 19:25
Hi, I have a QList like this:

QList<QString> list;
list << "town" << "country" << "name" << "surname" << "car";


for(int i=0;i<list.size();i++) {
//what do I have to put in here in order to output the list (every element) with a " " between them
}

eleanor
25th October 2007, 19:55
I got it:


for(i=0;i<list.size();i++) {
cout << list.at(i).toLocal8Bit().constData();
}

eleanor
25th October 2007, 19:56
I got I question though: I've heard that it isn't good practice to include int's in the QT program, should I include QInt or something like that?

^NyAw^
25th October 2007, 20:48
Hi,

Try this:


for(int i=0;i<list.size();i++)
{
cout << \"<< list.at(i) << \";
}




I got I question though: I've heard that it isn't good practice to include int's in the QT program, should I include QInt or something like that?


Why cant you use int variables in Qt code? Qt is C++ code and it also use integer variables.

jpn
25th October 2007, 21:08
Use QStringList instead of QList<QString>:


QStringList list;
list << "town" << "country" << "name" << "surname" << "car";
qDebug() << list.join(" ");

PS. Notice that making a QStringList out of QList<QString> is also very cheap thanks to implicit sharing.. just in case you've tied to using QList<QString> for some reason.