Results 1 to 3 of 3

Thread: Split QStringList in Chucks

  1. #1
    Join Date
    Mar 2010
    Location
    Heredia, Costa Rica
    Posts
    257
    Thanks
    24
    Thanked 17 Times in 14 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Split QStringList in Chucks

    Hi,

    Is there a function in QT to split a QStringList into sections/chunks? For example, I have a QStringList with 100 items. I what to split it into 3. So for example I could get a <QVector QStringLists> with 3 sections: 1 with 33 items, 2 with 33 items, and 3 with 34 items.

    I can write a function for that but I was wondering if it's already there. Something like array_split

    Thanks,

  2. #2
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    503
    Thanks
    11
    Thanked 76 Times in 74 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Split QStringList in Chucks

    Hi, std::list has a splice() method, but it looks like QStringList doesn't. So maybe try std::copy or std::copy_n?

    Ginsengelf

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,229
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Split QStringList in Chucks

    QStringList inherits from QList< QString>, and this template class has a QList::mid() method that returns a chunk of the QList.

    The chunk is a copy, so the original list is unchanged.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  4. The following user says thank you to d_stranz for this useful post:

    qlands (12th July 2022)

Similar Threads

  1. Replies: 7
    Last Post: 6th February 2017, 20:10
  2. split a Qstring into QStringList
    By mvpbabu in forum Qt Programming
    Replies: 1
    Last Post: 4th January 2017, 08:01
  3. how to split the text in Qstringlist
    By iswaryasenthilkumar in forum Newbie
    Replies: 8
    Last Post: 16th February 2015, 06:37
  4. split QByteArray
    By xproch13 in forum Newbie
    Replies: 2
    Last Post: 29th October 2010, 22:50
  5. Replies: 7
    Last Post: 2nd June 2006, 13:48

Tags for this Thread

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.