Results 1 to 7 of 7

Thread: QStringlist To QString

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    258
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android
    Thanks
    22
    Thanked 19 Times in 16 Posts

    Default Re: QStringlist To QString

    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:
    1. #include <QApplication>
    2. #include <QtGui>
    3.  
    4. class StringList : public QStringList
    5. {
    6. public:
    7. operator QString() const { return this->join(" "); }
    8. };
    9.  
    10. int main(int argc, char* argv[])
    11. {
    12. QApplication(argc, argv);
    13. StringList sl;
    14. sl << "one" << "two" << "three";
    15. qDebug() << (QString)sl;
    16.  
    17. return 0;
    18. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by momesana; 27th October 2007 at 11:12.

  2. The following user says thank you to momesana for this useful post:

    phillip_Qt (30th October 2007)

Similar Threads

  1. QStringList
    By dragon in forum Newbie
    Replies: 2
    Last Post: 8th June 2007, 17:26
  2. QString static callback function from CURL
    By tpf80 in forum Qt Programming
    Replies: 12
    Last Post: 16th May 2007, 20:47
  3. Convert from iso-8859-1 to... Something else :-)
    By Nyphel in forum Qt Programming
    Replies: 4
    Last Post: 7th March 2007, 17:59
  4. QSqlQueryModel + set Write
    By raphaelf in forum Qt Programming
    Replies: 7
    Last Post: 5th June 2006, 08:55
  5. Converting QString to unsigned char
    By salston in forum Qt Programming
    Replies: 3
    Last Post: 24th April 2006, 22:10

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.