Handling several QStringLists



  • In the application I am currently developing I want to store several QStringLists in a single QStringList!

    eg-
    QStringList a;
    QStringList b;
    QStringList c;

    b<<"John"<<"Smith"<<"Peter";
    c<<"Mary"<<"Anne"<<"Marie";
    a<<b<<c;
    Compiling this code does not return any errors but when I print a[0] on a label only "John" is printed instead of "John Smith Peter"
    I want to store 'b' and 'c' in 'a'!What is the best data structure to achive this?



  • @Lasith try checking what printing b[0], b[1] and b[2] show just before adding b and c lists to a, and I guess you'll have the answer...


  • Lifetime Qt Champion

    Hi,

    Looks like you should use QString::join.


  • Qt Champions 2017

    Hi
    There is something odd about your statements.
    You say you want lists in the list.
    But you also say you expect "John Smith Peter" which is not a list but one string.
    So are you saying you want the lists b and c to become one string and no longer be a list of 3 strings?

    Anyway, seems @SGaist is a master guesser :) \o/



  • @SGaist Thanx mate



Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.