Results 1 to 6 of 6

Thread: QStringList

  1. #1
    Join Date
    Dec 2007
    Location
    Brazil
    Posts
    61
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QStringList

    I wanted to copy a QStringList to another QStringList but only taking the odd positions.

    Qt Code:
    1. QStringList pa[1] = QStringList im[0];
    2. QStringList pa[3] = QStringList im[1];
    3. QStringList pa[5] = QStringList im[2];
    4. .
    5. .
    6. .
    To copy to clipboard, switch view to plain text mode 

    Someone has idea?
    Thanks.
    Last edited by jpn; 16th May 2008 at 20:33. Reason: missing [code] tags

  2. #2
    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: QStringList

    Hi,

    Use something similar to this:

    Qt Code:
    1. int i=0;
    2. int j=1;
    3. while (i<im.count())
    4. {
    5. pa[j] = im[i];
    6. i++;
    7. j +=2;
    8. }
    To copy to clipboard, switch view to plain text mode 

    Not tested
    Òscar Llarch i Galán

  3. #3
    Join Date
    Dec 2007
    Location
    Brazil
    Posts
    61
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QStringList

    Quote Originally Posted by ^NyAw^ View Post
    Hi,

    Use something similar to this:

    Qt Code:
    1. int i=0;
    2. int j=1;
    3. while (i<im.count())
    4. {
    5. pa[j] = im[i];
    6. i++;
    7. j +=2;
    8. }
    To copy to clipboard, switch view to plain text mode 

    Not tested
    tried in many ways, but always occurs Segmentation fault.

    Qt Code:
    1. while (i < pa.count())
    2. {
    3. im[i] = pa[j];
    4. i++;
    5. j +=2;
    6. }
    To copy to clipboard, switch view to plain text mode 

    there is no way in Qt?
    Last edited by jaca; 16th May 2008 at 21:56.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QStringList

    You have to resize the list or use append() to insert items and the indexes of the list have to be a sequence. If you want only odd index numbers, use QMap.
    Qt Code:
    1. int index = 1;
    2. QStringList inlist;
    3. QMap<int, QString> out;
    4. foreach(const QString &str, inlist){
    5. out[index] = str;
    6. index+=2;
    7. }
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Dec 2007
    Location
    Brazil
    Posts
    61
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QStringList

    Quote Originally Posted by wysota View Post
    You have to resize the list or use append() to insert items and the indexes of the list have to be a sequence. If you want only odd index numbers, use QMap.
    Qt Code:
    1. int index = 1;
    2. QStringList inlist;
    3. QMap<int, QString> out;
    4. foreach(const QString &str, inlist){
    5. out[index] = str;
    6. index+=2;
    7. }
    To copy to clipboard, switch view to plain text mode 
    tried this code:
    Qt Code:
    1. QMap<int, QString>::const_iterator i = out.constBegin();
    2. while (i != out.constEnd()) {
    3. cout << i.key() << ": " << i.value() << endl;
    4. ++i;
    5. }
    To copy to clipboard, switch view to plain text mode 

    Only I could not show values. As I see the values of QMap?
    Thanks.
    Last edited by jaca; 16th May 2008 at 21:55.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QStringList

    Do you have console support enabled? I suggest using QMessageBox instead of cout to be sure.

Similar Threads

  1. QStringList scope problem
    By ht1 in forum Qt Programming
    Replies: 5
    Last Post: 30th November 2007, 19:44
  2. Translating a QStringList
    By ^NyAw^ in forum Qt Programming
    Replies: 5
    Last Post: 18th January 2007, 11:06
  3. QStringList in QObject::connect
    By DPinLV in forum Qt Programming
    Replies: 6
    Last Post: 6th September 2006, 17:01
  4. Cannot queue arguments of type 'QStringList'
    By vfernandez in forum Qt Programming
    Replies: 2
    Last Post: 19th April 2006, 20:48
  5. need help to classify some QStringList
    By patcito in forum Qt Programming
    Replies: 3
    Last Post: 17th February 2006, 21:24

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.