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