QVariant to QList
-
This doesn't work either:
QList<QString> qls = static_cast<QList<QString>>(value.toList());
I think I'm overlooking something fairly basic here.
-
This doesn't work either:
QList<QString> qls = static_cast<QList<QString>>(value.toList());
I think I'm overlooking something fairly basic here.
@mzimmers
I don't think a list of variants is/can be the same thing as a list of strings, or converted between the two/treated as such? (AQVariant
cannot be aQString
, it can only contain one.) My thought is you would want to iterate, appending each element?
Note that this is purely a guess as I read this :) -
@mzimmers
I don't think a list of variants is/can be the same thing as a list of strings, or converted between the two/treated as such? (AQVariant
cannot be aQString
, it can only contain one.) My thought is you would want to iterate, appending each element?
Note that this is purely a guess as I read this :)@JonB I think you're saying basically the same thing that @JoeCFD is, and I think you're both right.
But I still don't know how to cast/convert my QVariant value into a QString (or a QList<QString>).
EDIT: though this comes close:
for (QString qs : value.toStringList()) { item.equipment.append(qs); }
EDIT 2: which means this comes even closer:
case EquipmentRole: item.equipment.clear(); item.equipment.append(value.toStringList());
-
@JonB I think you're saying basically the same thing that @JoeCFD is, and I think you're both right.
But I still don't know how to cast/convert my QVariant value into a QString (or a QList<QString>).
EDIT: though this comes close:
for (QString qs : value.toStringList()) { item.equipment.append(qs); }
EDIT 2: which means this comes even closer:
case EquipmentRole: item.equipment.clear(); item.equipment.append(value.toStringList());
-
@JoeCFD I can't tell for sure until I can expose this in QML, but I'm fairly sure it's working. I'll ask my other question in the QML forum.
Thanks for the help, guys.
EDIT: yeah, it seems to have worked.
-
got this from ChatGPT and you are good.
if (variant.canConvert<QStringList>()) {
QList<QString> stringList = variant.toStringList();
} -
got this from ChatGPT and you are good.
if (variant.canConvert<QStringList>()) {
QList<QString> stringList = variant.toStringList();
} -
Understand. Think about you can never be the number 1 or even close anymore if you play chess.