How to convert QVariant(CustomType *) to CustomType*

  • Im passing a map object into QML by using ;
    @viever.rootContext()->setContextProperty(.. , ..)@

    My map object is ;
    @QMap<QString, QVariant> map;
    map.insert("KEY", QVariant::fromValue(CustomTypeList*))@

    In QML im getting @QVariant(CustomTypeList*)@ by MyMapObject["KEY"]. It is the model for my repeater. It is ok but i have to reach an invokable method (insert Method) in order to manupulate this model object. My question is that how can i reach CustomType's methods from QVariant(CustomType*)?

    or any other suggestion?

  • Moderators

    QVariant variant = QVariant::fromValue(CustomTypeList *object);
    CustomTypeList *myVariable = variant.value<CustomTypeList *>();

  • thx for answer sierdzio, but i have to do this convertion in javascript side. Is there any way to do it?

  • Moderators

    AFAIK, JavaScript will not understand your custom type, so it cannot convert.

  • hmm.. but when i write the typeof my variant object, it will write on log screen "QVariant(CustomObject*)"

    im using
    The result is

Log in to reply

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