Custom itemModel, passing "complex variant" from QML



  • I have a custom item model extending QAbstractItemModel and Implementing setData method. On the QML I can assign data to roleNames and the setData method gets called correctly with the QVariant instance but only if the data is a basic type. Is there a way to pass a QVariantMap from QML to C++ through setData?

    Example in QML:
    rolename = "string" //works fine
    rolename = {key : "value"} //does not work (QVariant is empty on c++ side)
    rolename = {"key" : "value"} //does not work (QVariant is empty on c++ side)



  • setData uses QVariant as argument probably you need to convert to QVarianMap using QVariant::toMap on c++ side



  • Thanks, that worked perfectly.

    My error was trying to convert the Variant to a JsonObject instead of a VariantMap on the c++ side.


Log in to reply