Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. List of lists (or container of containers), is it possible in QT?
Forum Updated to NodeBB v4.3 + New Features

List of lists (or container of containers), is it possible in QT?

Scheduled Pinned Locked Moved General and Desktop
9 Posts 4 Posters 5.6k Views 1 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.
  • M Offline
    M Offline
    mkcerusky
    wrote on last edited by
    #1

    I was wondering if in QT it is possible to crate a container that can contain other containers of the same kind and other kinds of objects.
    Same question for lists.

    I have been searching on the forum and on the net, but I can't even find anyone speaking of this kind of issue, or maybe I find for the wrong words :(

    Thanks in advance for your help.

    1 Reply Last reply
    0
    • N Offline
      N Offline
      N3Roaster
      wrote on last edited by
      #2

      Lists of lists (or other containers) are the same as lists of anything else. No discussion because it works exactly as one might expect it to.

      1 Reply Last reply
      0
      • U Offline
        U Offline
        utcenter
        wrote on last edited by
        #3

        It is not possible in QT (QuickTime) but it is perfectly possible in Qt. Did you like... try it before you ask the question?

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mkcerusky
          wrote on last edited by
          #4

          I have been trying for months and never succeded building a list of lists, and didn't even find any example on the web of lists lof lists, do you know if anywhere I can see an example of simple list of lists that works and that gives no compliling errors?

          Here is my example of a class that should be a list of lists. It is supposed to convert an algebrai expression into a nested list, but when I try to iterate and try to append an object of the same kind as a child to the list I get errors. See the bold in the code below.

          The idea is for instance that the equation a=b+c should be converted into {a,{b,c}}.

          I previously did similar things with php which does not requires variable declaration and it works finely. I did it also with flex, but in Qt I couldn't get any attempt to work, I actually tried many variations, but I must admit I am quite ignorant for what concerns Qt language, thus I decided to ask if it is possible or not, before spending several other months failing :(

          @class LALGExpression : public QList<QString>
          {

          public:
          LALG[removed]) {
          }

          LALG[removed]const QString &lalgExpressionText) {
          
          
              if(lalgExpressionText.contains("=")) {
                  QStringList * tmp = new QStringList(lalgExpressionText.split("="));
          
                  for (int i = 0; i < tmp->size(); ++i) {
                      LALGExpression *nextExpr = new LALG[removed]tmp->at(i));
                      this->append(nextExpr);
                      this->append(tmp->at(i));
                  }
                  this->setLalgExpressionOp("U");
              }
              else if(lalgExpressionText.contains("+")) {
                  QStringList * tmp = new QStringList(lalgExpressionText.split("+"));
          
                  for (int i = 0; i < tmp->size(); ++i) {
                      this->append(tmp->at(i));
                  }
                  this->setLalgExpressionOp("P");
              }
              else this->append(lalgExpressionText);
          }
          

          @

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mkcerusky
            wrote on last edited by
            #5

            Sorry I didn't think the code would come unformatted, I don't know how to reformat it here

            1 Reply Last reply
            0
            • ZlatomirZ Offline
              ZlatomirZ Offline
              Zlatomir
              wrote on last edited by
              #6

              To create a list that contains lists you don't inherit from List<QString> (that create another class that is extending a list of strings), you need to create a QList and as a template parameter pass QList<QString>, so the code will become something like: @QList<QList<QString> > listOfListsOfString; //notice that there is a space between > >@

              LE: since you need a QString in the list a good solution might be a QList<QStringList> listOfListsOfString; (especially if you'll need QStringList's functionality, like join)

              https://forum.qt.io/category/41/romanian

              1 Reply Last reply
              0
              • M Offline
                M Offline
                mkcerusky
                wrote on last edited by
                #7

                Oh, thanks, but in this way, will my listOfListsOfString be only 2 steps deep, or with the same declaration will I be allowed to create a listOfListsOfListsOfListsOfListsOfListsOfStrings? I mean with an unfixed dept?

                Thanks in advance

                1 Reply Last reply
                0
                • N Offline
                  N Offline
                  N3Roaster
                  wrote on last edited by
                  #8

                  You should see an edit link next to your posts to let you fix formatting. There's a code button above the text area that shows how.

                  You're declaring your lists as:

                  @QList<QString>@

                  but then you're trying to insert something that isn't a QString into that list. That won't work. For a list of lists of strings you'd use:

                  @QList<QList<QString> >@

                  but that doesn't seem like it would be flexible enough for what you're really intending to do here. You may want to check the documentation of QVariant which can contain QString or QList<QVariant> (or many other things) and can be used to construct arbitrary trees such as you seem to want.

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    mkcerusky
                    wrote on last edited by
                    #9

                    Thanks this QVariant sounds really interesting, I will try to explore it, thanks a lot :)

                    ...and yes, I succeded formatting the code above, it wasn't that difficult, doh!

                    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