HI All
CAn any body tell me how to change QStringlist object to QString type.
my code is QStringList list1 = str.split(".");
i need to change list1 to Qstring type.
I tried like this reinterpret_cast<QString>(list1). but giving error.
THank you all.
HI All
CAn any body tell me how to change QStringlist object to QString type.
my code is QStringList list1 = str.split(".");
i need to change list1 to Qstring type.
I tried like this reinterpret_cast<QString>(list1). but giving error.
THank you all.
Cheers,
Phillip
--- Please post the solution you got to solve your problem. It may help others.
I am not sure I understand what you really intent to do, but If you want to change a QStringList into a QString, I guess join() is the operation you are looking for:
QString QStringList::join ( const QString & separator ) const
a QStringList is fundamantally different from a QString. It is actually a QList<QString> with some added convenience functions like split and join. So casting doesn't really makes sense. You can implement a cast operation for it on your own if you derive from QStringList and add a cast operator returning something like the joined string but I don't see what purpose that would be good for.
Qt Code:
#include <QApplication> #include <QtGui> { public: }; int main(int argc, char* argv[]) { StringList sl; sl << "one" << "two" << "three"; return 0; }To copy to clipboard, switch view to plain text mode
Last edited by momesana; 27th October 2007 at 12:12.
phillip_Qt (30th October 2007)
A QStringList strlist is a list of QString .... so strlist[0] is a QString.
Gokulnathvc (19th March 2011), phillip_Qt (30th October 2007)
Hi,
Here you know that your QStringList will be only a single QString when you split it because you know that only there is one QString, I'm right?
So,
Qt Code:
To copy to clipboard, switch view to plain text mode
Òscar Llarch i Galán
phillip_Qt (30th October 2007)
Here is the solution :
Qt Code:
QStringList strList; strList << "bird" << "tree" << "water" ; str = strList.join(","); // str = "bird,tree,water";To copy to clipboard, switch view to plain text mode
Last edited by CuteKid; 23rd May 2014 at 00:36.
Nice. I am sure that after 6 1/2 years of waiting since 2007, phillip_Qt was overjoyed to get your answer.![]()
Bookmarks