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.
#include <QApplication>
#include <QtGui>
{
public:
operator
QString() const { return this
->join
(" ");
}};
int main(int argc, char* argv[])
{
StringList sl;
sl << "one" << "two" << "three";
return 0;
}
#include <QApplication>
#include <QtGui>
class StringList : public QStringList
{
public:
operator QString() const { return this->join(" "); }
};
int main(int argc, char* argv[])
{
QApplication(argc, argv);
StringList sl;
sl << "one" << "two" << "three";
qDebug() << (QString)sl;
return 0;
}
To copy to clipboard, switch view to plain text mode
Bookmarks