Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. QtonPi
  4. QstringList
Qt 6.11 is out! See what's new in the release blog

QstringList

Scheduled Pinned Locked Moved Unsolved QtonPi
2 Posts 2 Posters 1.1k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • sandy_winthS Offline
    sandy_winthS Offline
    sandy_winth
    wrote on last edited by
    #1

    Hi
    I have a question in qt c++.
    I want to assign each item of stringlist to another stringlists
    like:
    stringlist_1 =("k#k1#k2" , "s#s1#s2" , "b#b1#b2")
    I want to make them like this :
    stringlist_2 = ("k","k","k2")
    stringlist_3 = ("s","s1","s2")
    etc..

    how can I make that?
    I tray to use this code

    for (int i=0 ; i<2 ; i++)
    {
        QStringList d = stringlist_1.value(i).split("#");
        qDebug()<< d ; 
     } 
    

    I use for loop becuase my list it is very big, but
    the problem , it is storing all strings of primary list in same stringlist (d).
    how can I let for loop change the stringlist which assigned to it in each loop?
    or there is another method can I make that?
    thanks

    1 Reply Last reply
    0
    • yeckelY Offline
      yeckelY Offline
      yeckel
      wrote on last edited by
      #2

      What about storing the stringList in another container like list?

      #include QCoreApplication
      #include QStringList
      #include QDebug
      
      int main(int argc, char *argv[]){
          QStringList a{"k#k1#k2" , "s#s1#s2" , "b#b1#b2"};
          QList<QStringList> list;
          foreach (const QString &s, a) {
          list.append(s.split("#"));
         }
          qDebug() << list;
      }
      
      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved