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. Increasing QList<QStringList> contents twice!
QtWS25 Last Chance

Increasing QList<QStringList> contents twice!

Scheduled Pinned Locked Moved Unsolved General and Desktop
qlistqstringlistloop
12 Posts 6 Posters 4.1k Views
  • 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.
  • V Offline
    V Offline
    VRonin
    wrote on 12 Dec 2017, 15:18 last edited by
    #2

    remove the loop with i

    "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
    ~Napoleon Bonaparte

    On a crusade to banish setIndexWidget() from the holy land of Qt

    K 1 Reply Last reply 12 Dec 2017, 16:01
    2
    • V VRonin
      12 Dec 2017, 15:18

      remove the loop with i

      K Offline
      K Offline
      Kushan
      wrote on 12 Dec 2017, 16:01 last edited by
      #3

      @VRonin Thanx but if I add another QStringList list2<<"f"<<"g"<<"h"<<"i"<<"j"; to List1 how can I get twice of its contents also?

      K 1 Reply Last reply 12 Dec 2017, 17:11
      0
      • K Kushan
        12 Dec 2017, 16:01

        @VRonin Thanx but if I add another QStringList list2<<"f"<<"g"<<"h"<<"i"<<"j"; to List1 how can I get twice of its contents also?

        K Offline
        K Offline
        koahnig
        wrote on 12 Dec 2017, 17:11 last edited by
        #4

        @Kushan

        Not really sure what you are trying to do. Also the outcome seem not to match what I would expect.

        Anyway checkout the doucmentation for QStringList &QStringList::operator<<(const QList<QString> &other)

        QStringList list1;
        list1<<"a"<<"b"<<"c"<<"d"<<"e"; // list1 should contain "a" "b" "c" "d" "e" beause you copy individual strings
        QStringList List1;               // List1 is empty
        // copy one QStringList to another
        List1 << list1; // List1 should contain "a" "b" "c" "d" "e" because you copied with operator<< as described above
        // repeat to add another copy
        List1 << list1; // List1 should contain "a" "b" "c" "d" "e" "a" "b" "c" "d" "e" because you appended twice
        

        Vote the answer(s) that helped you to solve your issue(s)

        V 1 Reply Last reply 12 Dec 2017, 17:44
        0
        • K koahnig
          12 Dec 2017, 17:11

          @Kushan

          Not really sure what you are trying to do. Also the outcome seem not to match what I would expect.

          Anyway checkout the doucmentation for QStringList &QStringList::operator<<(const QList<QString> &other)

          QStringList list1;
          list1<<"a"<<"b"<<"c"<<"d"<<"e"; // list1 should contain "a" "b" "c" "d" "e" beause you copy individual strings
          QStringList List1;               // List1 is empty
          // copy one QStringList to another
          List1 << list1; // List1 should contain "a" "b" "c" "d" "e" because you copied with operator<< as described above
          // repeat to add another copy
          List1 << list1; // List1 should contain "a" "b" "c" "d" "e" "a" "b" "c" "d" "e" because you appended twice
          
          V Offline
          V Offline
          VRonin
          wrote on 12 Dec 2017, 17:44 last edited by
          #5

          @koahnig List1 is of type QList<QstringList> (i guessed from the title)

          @Kushan said in increasing QList<QStringList> contents twice!:

          Thanx but if I add another QStringList list2<<"f"<<"g"<<"h"<<"i"<<"j"; to List1 how can I get twice of its contents also?

          List1<<list1;
          List1[0]<<list2;
          List1[0] << List1[0]; //this is the duplication
          

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          K 1 Reply Last reply 12 Dec 2017, 17:45
          4
          • V VRonin
            12 Dec 2017, 17:44

            @koahnig List1 is of type QList<QstringList> (i guessed from the title)

            @Kushan said in increasing QList<QStringList> contents twice!:

            Thanx but if I add another QStringList list2<<"f"<<"g"<<"h"<<"i"<<"j"; to List1 how can I get twice of its contents also?

            List1<<list1;
            List1[0]<<list2;
            List1[0] << List1[0]; //this is the duplication
            
            K Offline
            K Offline
            Kushan
            wrote on 12 Dec 2017, 17:45 last edited by
            #6

            @VRonin yeah its QList<QstringList>

            J 1 Reply Last reply 12 Dec 2017, 18:03
            0
            • K Kushan
              12 Dec 2017, 17:45

              @VRonin yeah its QList<QstringList>

              J Offline
              J Offline
              JonB
              wrote on 12 Dec 2017, 18:03 last edited by JonB 12 Dec 2017, 18:04
              #7

              @Kushan
              How come there's a post https://forum.qt.io/topic/85879/runtime-error-terminate-called-after-throwing-an-instance-of-std-bad_alloc by a different person? Do you have a double? Have you each been set homework? :)

              K K 2 Replies Last reply 12 Dec 2017, 18:24
              3
              • J JonB
                12 Dec 2017, 18:03

                @Kushan
                How come there's a post https://forum.qt.io/topic/85879/runtime-error-terminate-called-after-throwing-an-instance-of-std-bad_alloc by a different person? Do you have a double? Have you each been set homework? :)

                K Offline
                K Offline
                Kushan
                wrote on 12 Dec 2017, 18:24 last edited by
                #8

                @JNBarchan I read that post! In my problem there are no errors only the output is incorrect

                1 Reply Last reply
                0
                • J JonB
                  12 Dec 2017, 18:03

                  @Kushan
                  How come there's a post https://forum.qt.io/topic/85879/runtime-error-terminate-called-after-throwing-an-instance-of-std-bad_alloc by a different person? Do you have a double? Have you each been set homework? :)

                  K Offline
                  K Offline
                  kshegunov
                  Moderators
                  wrote on 12 Dec 2017, 23:33 last edited by
                  #9

                  @JNBarchan said in increasing QList<QStringList> contents twice!:

                  Have you each been set homework?

                  My guess is the same class at University of Colombo School of Computing. I was too lazy to run a cross-correlation analysis on the posts, though, so don't take any of this at face value ... but then again ... if it looks like a duck, swims like a duck, and quacks like a duck, then it probably is a duck.

                  Read and abide by the Qt Code of Conduct

                  J J 2 Replies Last reply 13 Dec 2017, 08:05
                  2
                  • K kshegunov
                    12 Dec 2017, 23:33

                    @JNBarchan said in increasing QList<QStringList> contents twice!:

                    Have you each been set homework?

                    My guess is the same class at University of Colombo School of Computing. I was too lazy to run a cross-correlation analysis on the posts, though, so don't take any of this at face value ... but then again ... if it looks like a duck, swims like a duck, and quacks like a duck, then it probably is a duck.

                    J Offline
                    J Offline
                    JonB
                    wrote on 13 Dec 2017, 08:05 last edited by
                    #10

                    @kshegunov
                    Excluding the code (which is virtually identical, including the lack of spaces), they both have:

                    In my Qt C++ application I have a QList<QstringList> I want to increase the contents of its 0th index by the same amount!
                    ...
                    from the above code I want to make the contents of 0th index of List (i.e List[0]) a QStringList of "a" "b" "c" "d" "e" "a" "b" "c" "d" "e" ... How can I correct this?

                    That's the same down to the "!"-mark! Something fishy is going on with ducks here... ;-)

                    It's interesting to hear that Qt is being used in an education course. But why Qt for this question? There's nothing special about QList or QStringList, this could just as well have been posed for std C++. If you're going to teach Qt I would have expected a Qt-ish question, else don't bother.

                    K 1 Reply Last reply 13 Dec 2017, 09:44
                    1
                    • J JonB
                      13 Dec 2017, 08:05

                      @kshegunov
                      Excluding the code (which is virtually identical, including the lack of spaces), they both have:

                      In my Qt C++ application I have a QList<QstringList> I want to increase the contents of its 0th index by the same amount!
                      ...
                      from the above code I want to make the contents of 0th index of List (i.e List[0]) a QStringList of "a" "b" "c" "d" "e" "a" "b" "c" "d" "e" ... How can I correct this?

                      That's the same down to the "!"-mark! Something fishy is going on with ducks here... ;-)

                      It's interesting to hear that Qt is being used in an education course. But why Qt for this question? There's nothing special about QList or QStringList, this could just as well have been posed for std C++. If you're going to teach Qt I would have expected a Qt-ish question, else don't bother.

                      K Offline
                      K Offline
                      koahnig
                      wrote on 13 Dec 2017, 09:44 last edited by
                      #11

                      @JNBarchan @kshegunov nice research guys.

                      I had already the feeling that the initial post is really sloppy formulated like someone is fishing for an easy answer.

                      Vote the answer(s) that helped you to solve your issue(s)

                      1 Reply Last reply
                      0
                      • K kshegunov
                        12 Dec 2017, 23:33

                        @JNBarchan said in increasing QList<QStringList> contents twice!:

                        Have you each been set homework?

                        My guess is the same class at University of Colombo School of Computing. I was too lazy to run a cross-correlation analysis on the posts, though, so don't take any of this at face value ... but then again ... if it looks like a duck, swims like a duck, and quacks like a duck, then it probably is a duck.

                        J Offline
                        J Offline
                        J.Hilk
                        Moderators
                        wrote on 13 Dec 2017, 09:50 last edited by
                        #12

                        @kshegunov said in increasing QList<QStringList> contents twice!:

                        if it looks like a duck, swims like a duck, and quacks like a duck

                        s

                        Slight thread derail, but I would say the op's question general is answered .


                        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                        Q: What's that?
                        A: It's blue light.
                        Q: What does it do?
                        A: It turns blue.

                        1 Reply Last reply
                        0

                        11/12

                        13 Dec 2017, 09:44

                        • Login

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