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. Parameterizing a QML component with a registered C++ class having a QProperty
Forum Updated to NodeBB v4.3 + New Features

Parameterizing a QML component with a registered C++ class having a QProperty

Scheduled Pinned Locked Moved QML and Qt Quick
1 Posts 1 Posters 422 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.
  • B Offline
    B Offline
    bootchk
    wrote on last edited by
    #1

    I have defined in Python (alternatively C++) a class A which has a notifiable Qt property B. I registered the class A with QML. I want to parameterize a QML Component with the property B of class A.

    This doesn't work, it quietly fails to emit a signal 'changed' from property B.

    main.qml

    @import MyComponent 1.0
    import A 1.0 // C++ class A is registered

    Item {
    model: A{}
    MyComponent.MyComponent{ componentModel: model.b } // specialize component with model: property b of instance of class A
    }@

    MyComponent.qml

    @MyComponent {
    property var componentModel
    ...
    onActivated { componentModel = 1 }
    }@

    This works: same as above except:

    @ MyComponent.MyComponent{ componentModel: model } // specialize with class A@

    and

    @ onActivated { componentModel.b = 1 } // component accesses property b of instance of A@

    Why doesn't the first example work? That is, why can't I pass a QProperty to parameterize a component?

    There is a discussion here: http://doc.qt.io/qt-5/qtqml-cppintegration-exposecppattributes.html, but I think that I have properly exposed (to QML engine) the class A and its property B.

    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