[Solved]QVariant to QList

  • 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?


  • Moderators

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

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

  • Moderators

    QStringList templist = myMap.value("value").toMap().value("otherValue").toStringList();

    Brain to terminal. YMMV.

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

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

  • Moderators

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

  • Thank you, it works now

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.