PDA

View Full Version : How to read QStringList character by character



iamjayanth
3rd April 2009, 10:06
Masters,

I have a QStringList and I want to read from it one character at a time (just like using getch() from files). I am using qt 3.3 . Can anybody help me out . Thanking you..

spirit
3rd April 2009, 10:20
try this


QStringList list;
list << "abc" << "def";

for (QStringList::Iterator it = list.begin(); it != list.end(); ++it) {
const QString str = *it;
for (int i = 0; i < str.length(); ++i)
cout << str.at(i);
}

iamjayanth
3rd April 2009, 11:05
Thanks spirit...It is reading character by character. But it is not reading end of line character('\n'). How can we modify the code so that we can read end of line character also..Thanking you again...

spirit
3rd April 2009, 11:13
for docs


... The QChar array of the QString (as returned by unicode()) is generally not terminated by a '\0'. If you need to pass a QString to a function that requires a C '\0'-terminated string use latin1()...

read this (http://doc.trolltech.com/3.3/qstring.html#details) for more info.

iamjayanth
3rd April 2009, 11:25
Thanks spirit ....That did it.....Thank you very much.....