Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Exposing a custom data type to QML
Forum Updated to NodeBB v4.3 + New Features

Exposing a custom data type to QML

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 299 Views 2 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.
  • S Offline
    S Offline
    swurl
    wrote on last edited by swurl
    #1

    Qt Version is 6.7.2.

    What I'm looking for is essentially to have a struct or class, e.g.

    typedef struct CustomType {
        Q_GADGET
        QString customValue;
        // Q_PROPERTY stuff here...
    }
    

    and then declare it to Qt in such a way that I can have a variable -- NOT a component -- with that type, and be able to explicitly declare it as such, i.e.

    Item {
        property CustomType customType
    
        Component.onCompleted: {
            customType.customValue = "Test Value"
            console.log(customType.customValue, typeof customType) // Test Value CustomType
        }
    }
    

    In essence, bringing my own custom types into QML land much like QRect -> rect, QColor -> color, etc. but NOT as a component as the documentation outlines.

    How would I go about doing this?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      Asperamanca
      wrote on last edited by
      #2

      https://doc.qt.io/qt-6/qtqml-cppintegration-definetypes.html#registering-value-types
      Does this help?

      S 1 Reply Last reply
      2
      • A Asperamanca

        https://doc.qt.io/qt-6/qtqml-cppintegration-definetypes.html#registering-value-types
        Does this help?

        S Offline
        S Offline
        swurl
        wrote on last edited by
        #3

        @Asperamanca Wow--I completely missed that--yes, that will work! Thanks.

        1 Reply Last reply
        0
        • S swurl has marked this topic as solved on

        • Login

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