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. model gets not assigned to custom class

model gets not assigned to custom class

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 564 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.
  • T Offline
    T Offline
    themts
    wrote on last edited by
    #1

    Hi guys,

    I have a custom component which implements a Q_PROPERTY like this:

    class NChartPlotter : public QQuickFramebufferObject
    {
        Q_OBJECT
        Q_PROPERTY(NChartAbstractDataModel* dataModel READ dataModel WRITE setDataModel)
    

    In main.cpp I create an instance of a NChartAbstractDataModel derived class and I set it as a contextProperty:

    NTestChartDataModel dm; //NTestChartDataModel is a subclass of NChartAbstractDataModel
    engine.rootContext()->setContextProperty("charDataModel", &dm);
    

    in QML I want to assign my model to a my view-component:

            ChartPlot {
                id: renderer
                anchors.fill: parent
                textureFollowsItemSize: true
                dataModel: charDataModel
            }
    

    PROBLEM:
    setDataModel gets never called.

    What am I doing wrong here?
    btw. this is my first qml-application.

    CU
    mts

    1 Reply Last reply
    0
    • T Offline
      T Offline
      themts
      wrote on last edited by themts
      #2

      ok, maybe I should have looked in the application-output earlier...
      -> "Unable to assign NTestChartDataModel to [unknown property type]"

      I do I let qml know about this class?

      EDIT:
      ok, I found that I have to use qRegisterMetaType to register my classType but I don't understand why I have to implement a copy-constructor?!
      Anyway, even if I implement a copy constructor to make the usage of qRegisterMetaType possible, I still get the "unknown property type" error on runtime.

      1 Reply Last reply
      0
      • C Offline
        C Offline
        chrisadams
        wrote on last edited by
        #3

        You need to use qmlRegisterType, not just qRegisterMetaType, for any type which you expose to QML in such a way that you expect property resolution (including method invocation) to occur on an instance of that type.

        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