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. Accessing to QML data model object from C++ directly
Forum Update on Monday, May 27th 2025

Accessing to QML data model object from C++ directly

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 2 Posters 488 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.
  • K Offline
    K Offline
    Kofr
    wrote on 23 Sept 2015, 13:02 last edited by Kofr
    #1

    Hi guys.
    In my app I have C++ model and QML view.
    Model is registered in C++ with qmlRegisterType<DataModel>("cpp.DataModel", 1, 0, "DataModel");
    It is Ok to use it from QML, but how can I use this class's object from C++ again?
    example:

    ....
    qmlRegisterType<DataModel>("cpp.DataModel", 1, 0, "DataModel");
    DataModel *dataModelObject = <<<code to get object registered as QML type>>> //how to embody this?
    ....
    
    1 Reply Last reply
    0
    • H Offline
      H Offline
      hpollak
      wrote on 23 Sept 2015, 13:18 last edited by
      #2

      With the code above you only register the Datatype!
      You create the instance(s) in the qml-Part.

      if you are using QQmlApplicationEngine you can search the rootObject for your instance you created in qml, or ( i think the simpler way ) create a instance and reqister it as ContextProperty.

      see Interacting with QML Objects from C++

      1 Reply Last reply
      1

      1/2

      23 Sept 2015, 13:02

      • Login

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