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. How can i remove a value from a qlist?

How can i remove a value from a qlist?

Scheduled Pinned Locked Moved General and Desktop
10 Posts 4 Posters 6.8k 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.
  • K Offline
    K Offline
    kanakas
    wrote on last edited by
    #1

    Hi,

    How can i remove a value from a QList< QMap<QString,QString> > test;?

    i tried this : @test.removeOne(label);@ but i get an error

    otherwise, how can i get the position of it to remove it?

    label is a qstring.

    1 Reply Last reply
    0
    • K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      Since your value of QList is of type QMap < QString, QString > you need to use such a type for using "removeOne()":http://developer.qt.nokia.com/doc/qt-4.8/qlist.html#removeOne .
      So it is probably more convenient for you to use "removeAt()":http://developer.qt.nokia.com/doc/qt-4.8/qlist.html#removeAt

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

      1 Reply Last reply
      0
      • K Offline
        K Offline
        kanakas
        wrote on last edited by
        #3

        I also tried this:

        @test.removeOne("test_id",label_cbx);@

        but i always get an error (no matching function)!!

        1 Reply Last reply
        0
        • G Offline
          G Offline
          goetz
          wrote on last edited by
          #4

          Why should it match? You give two arguments to a method that takes one... That should make you wonder firsthand...

          To remove an entry from a QList< QMap<QString,QString> >, that is a list of maps, you must construct a map or use a reference found elsewhere that denotes the map to remove from the list.

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply
          0
          • S Offline
            S Offline
            stima_ua
            wrote on last edited by
            #5

            hm...what are you want to do with QList<QMap<QString, QString>>? Mb I can told you better idea.

            1 Reply Last reply
            0
            • K Offline
              K Offline
              koahnig
              wrote on last edited by
              #6

              As Volker already lined out.
              However, I think this question is related to "your other post ":http://developer.qt.nokia.com/forums/viewthread/13330/ If this is really the case you are in a dead end anyhow.
              To delete anything in your QList of QMaps with removeOne will be a bit painful, if you are not referencing.

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

              1 Reply Last reply
              0
              • S Offline
                S Offline
                stima_ua
                wrote on last edited by
                #7

                about delete you want to delete all map that contains key? or just key from map?

                1 Reply Last reply
                0
                • K Offline
                  K Offline
                  kanakas
                  wrote on last edited by
                  #8

                  stima_ua, I want to remove a specific key of the map.

                  1 Reply Last reply
                  0
                  • K Offline
                    K Offline
                    kanakas
                    wrote on last edited by
                    #9

                    I would appreciate it if sb writes a small example to understand it better

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      stima_ua
                      wrote on last edited by
                      #10

                      @
                      #include <QMap>
                      #include <QList>

                      #include <QDebug>

                      typedef QMap<QString, QString> Map;

                      void removeKey(QList<Map>& list, const QString& key)
                      {
                      int ret = 0;
                      QList<Map>::iterator i;
                      for ( i = list.begin(); i != list.end() && !ret; i++ )
                      {
                      ret = (*i).remove(key); // but only find first
                      }
                      }

                      int main()
                      {
                      QList<Map> list;

                      Map aMap;
                      Map bMap;
                      
                      aMap["aKey1"] = "aValue1";
                      aMap["aKey2"] = "aValue2";
                      
                      bMap["bKey1"] = "bValue1";
                      bMap["bKey2"] = "bValue2";
                      
                      list.append(aMap);
                      list.append(bMap);
                      
                      qDebug() << list;
                      
                      removeKey(list, "aKey1");
                      
                      qDebug() << list;
                      
                      return 0;
                      

                      }
                      @

                      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