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.
Printable View
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.
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.
Code:
#include <QApplication> #include <QtGui> { public: }; int main(int argc, char* argv[]) { StringList sl; sl << "one" << "two" << "three"; return 0; }
A QStringList strlist is a list of QString .... so strlist[0] is a QString.
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,
Code:
Here is the solution :
Code:
QStringList strList; strList << "bird" << "tree" << "water" ; str = strList.join(","); // str = "bird,tree,water";
Nice. I am sure that after 6 1/2 years of waiting since 2007, phillip_Qt was overjoyed to get your answer. ;)