Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to convert QVariant(CustomType *) to CustomType*
QtWS25 Last Chance

How to convert QVariant(CustomType *) to CustomType*

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 2 Posters 2.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    muzo
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

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

      (Z(:^

      1 Reply Last reply
      0
      • M Offline
        M Offline
        muzo
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

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

          (Z(:^

          1 Reply Last reply
          0
          • M Offline
            M Offline
            muzo
            wrote on last edited by
            #5

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

            im using
            @console.log(myVariantObj["KEY"])@
            The result is
            @QVariant(CustomType*)@

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved