Split QStringList : QStringList « Qt « C++

Split QStringList


#include <QStringList>
#include <QDebug>

int main() {
    QString winter = "A, B, C";
    QString spring = "D, E, F";
    QString summer = "G, H, I";
    QString fall = "X, Y, Z";

    QStringList list;
    list << winter;        
    list += spring;        
    list << fall;

    QString allmonths = list.join(", "); 

    QStringList list2 = allmonths.split(", ");  
    Q_ASSERT(list2.size() == 12); 

    foreach (QString str, list) {  
        qDebug() << QString(" [%1] ").arg(str);
    return 0;


Related examples in the same category

1.Adding QStringList to QListWidget
2.A simple model that uses a QStringList as its data source
3.Complete demo for QStringList
4.QStringList demo
5.Quick sort QStringList
6.STL-Style Iterators
7.Search in a list of fruit names first for the word Pear and then for Orange
8.using QStringList, append to and output and join