Results 1 to 5 of 5

Thread: QList

  1. #1
    Join Date
    Nov 2006
    Posts
    96

    Default QList

    Hi, I have a QList like this:

    QList<QString> list;
    list << "town" << "country" << "name" << "surname" << "car";

    Qt Code:
    1. for(int i=0;i<list.size();i++) {
    2. //what do I have to put in here in order to output the list (every element) with a " " between them
    3. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Nov 2006
    Posts
    96

    Default Re: QList

    I got it:

    Qt Code:
    1. for(i=0;i<list.size();i++) {
    2. cout << list.at(i).toLocal8Bit().constData();
    3. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Nov 2006
    Posts
    96

    Default Re: QList

    I got I question though: I've heard that it isn't good practice to include int's in the QT program, should I include QInt or something like that?

  4. #4
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QList

    Hi,

    Try this:
    Qt Code:
    1. for(int i=0;i<list.size();i++)
    2. {
    3. cout << \"<< list.at(i) << \";
    4. }
    To copy to clipboard, switch view to plain text mode 

    I got I question though: I've heard that it isn't good practice to include int's in the QT program, should I include QInt or something like that?
    Why cant you use int variables in Qt code? Qt is C++ code and it also use integer variables.
    Òscar Llarch i Galán

  5. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QList

    Use QStringList instead of QList<QString>:
    Qt Code:
    1. list << "town" << "country" << "name" << "surname" << "car";
    2. qDebug() << list.join(" ");
    To copy to clipboard, switch view to plain text mode 
    PS. Notice that making a QStringList out of QList<QString> is also very cheap thanks to implicit sharing.. just in case you've tied to using QList<QString> for some reason.
    J-P Nurmi

Similar Threads

  1. Sorting using qSort(), - if QList contains POINTERS
    By joseph in forum Qt Programming
    Replies: 13
    Last Post: 18th August 2013, 18:55
  2. Q3Ptrlist v/s QList
    By joseph in forum Qt Programming
    Replies: 3
    Last Post: 25th September 2007, 11:27
  3. QList
    By dragon in forum Qt Programming
    Replies: 11
    Last Post: 9th May 2007, 20:15
  4. QList crash in destructor
    By mclark in forum Newbie
    Replies: 7
    Last Post: 6th December 2006, 15:27
  5. Accessing QList Objects
    By magikalpnoi in forum Qt Programming
    Replies: 7
    Last Post: 21st September 2006, 20:43

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.