Results 1 to 4 of 4

Thread: initialize QStringList with integers

  1. #1
    Join Date
    Nov 2007
    Posts
    103
    Thanks
    71
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default initialize QStringList with integers

    I'd like to generate a QStringList where every member is a concequtive integer. How do you load integers as QStringList contents?
    This won't work:
    Qt Code:
    1. QStringList mylist;
    2. for(int i=0; i<100; i++)
    3. mylist.append(i);
    To copy to clipboard, switch view to plain text mode 

    Thanks

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

    J-P Nurmi

  3. #3
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: initialize QStringList with integers

    Will this work ?
    mylist.append(QString(i));

  4. #4
    Join Date
    Jul 2006
    Location
    Catalunya - Spain
    Posts
    117
    Thanks
    16
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: initialize QStringList with integers

    Quote Originally Posted by aamer4yu View Post
    Will this work ?
    mylist.append(QString(i));
    No. It will not work. Because that call will cast the number to QChar and put into the string the char equivalent to the number, not the number in string format.

    As JPN said, you have to take a look at QString.number().

    i.e :
    Qt Code:
    1. mylist.append(QString.number(i));
    To copy to clipboard, switch view to plain text mode 
    will work.

Similar Threads

  1. QStringList
    By jaca in forum Qt Programming
    Replies: 5
    Last Post: 17th May 2008, 10:12
  2. QStringList scope problem
    By ht1 in forum Qt Programming
    Replies: 5
    Last Post: 30th November 2007, 19:44
  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
  •  
Qt is a trademark of The Qt Company.