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. [Solved]QVariant to QList

[Solved]QVariant to QList

Scheduled Pinned Locked Moved General and Desktop
7 Posts 2 Posters 2.4k 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.
  • B Offline
    B Offline
    Beka
    wrote on last edited by
    #1

    I have a QVariantMap, and values are QVariantMaps or QStringList, or map with lists... but when I call .toStringList() or .toList() it works fine, but after calling .clear(), removeAt(), takeAt() or something similar, it does nothing! what i am doing wrong?

    @myMap.value("value").toMap().value("otherValue").toStringList().removeOne("something");@

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mlong
      wrote on last edited by
      #2

      toStringList() returns a copy of the list, not a reference. So any changes you make are immediately discarded.

      Software Engineer
      My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

      1 Reply Last reply
      0
      • B Offline
        B Offline
        Beka
        wrote on last edited by
        #3

        Okay, so how can I remove something from that list?

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

          @
          QStringList templist = myMap.value("value").toMap().value("otherValue").toStringList();
          templist.removeOne("something");
          myMap.value("value").toMap().insert("otherValue",templist);
          @

          Brain to terminal. YMMV.

          Basically grab a copy of the list, modify the copy, then reinsert back into your map.

          Software Engineer
          My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

          1 Reply Last reply
          0
          • B Offline
            B Offline
            Beka
            wrote on last edited by
            #5

            yes, it was my first guess, but it doesnt work...

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mlong
              wrote on last edited by
              #6

              Ah, the toMap() also returns a copy, btw. Same issue, just next level up. Need a temp QMap, as well.

              Software Engineer
              My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

              1 Reply Last reply
              0
              • B Offline
                B Offline
                Beka
                wrote on last edited by
                #7

                Thank you, it works now

                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