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. HowTo: Struct -> QVariant -> QML type
Forum Updated to NodeBB v4.3 + New Features

HowTo: Struct -> QVariant -> QML type

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 2 Posters 2.1k Views 1 Watching
  • 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.
  • L Offline
    L Offline
    lack
    wrote on last edited by
    #1

    Hi all,

    I have a struct which I wanted to use in QML.
    Is my understanding correct that:
    I could wrap my struct in QVariant, then I could just make a similarly structured js object in QML, then pass that to c++ side.

    Or am I totally wrong and I need a different approach?

    Thanks before,
    evan

    1 Reply Last reply
    0
    • V Offline
      V Offline
      Vincent007
      wrote on last edited by
      #2

      I think you should wrap your struct in an QObject-derived class, and then register this class to QML engine so that you can instantiate the class in QML. You can create a method, which is callable in QML, in the class to assign values to your struct via QML code.

      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