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. When using QML & C++ what is the best practice of connecting the view/controller to the model?
QtWS25 Last Chance

When using QML & C++ what is the best practice of connecting the view/controller to the model?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
design patternc++ to qmlbest practice
2 Posts 2 Posters 530 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.
  • H Offline
    H Offline
    Hasan Al-Baghdadi
    wrote on last edited by
    #1

    I've gone throgh 3 diffirent itterations overtime each less bad than the last but still having issues.

    Iteration 1

    Having multiple diffirent classes for each subsystem with their models completley combined with their view/controller in code and all connections handled via qml.

    This one has no seperation between model and view/controller code and handles a great deal of model code in the qml end, which is definitley far from ideal, and makes modifiying code hell.

    Iteration 2

    Registering all C++ subsystems as singletons, and handling their interactions and connections in a few diffirent connection management claasses.

    This one was a much better approach as at least the model part of the code is no longer run in Qml, however Models and views/controllers are still in the same classes and we haven't achieved a full seperation.

    Iteration 3

    Defining the model/view classes (i.e. the classes that expose themselves to C++ in a completley seperate library from all other subsystems. These subsystem then register themselves with a GUI singleton Manager, that I will call GuiSystem here in the constructor via the use of a passkey idiom.

    Once registed with the GuiSystem the singleton will generate a signal that will then be used be connected to a subsystem via one of the earlier mentioned connection managing classes, this class will then setup connections between the SubSystems & the Gui objects.

    This approach will get rid of most singletons and fully seperate models and views from controllers, however it would create a single large singleton that I can see being almost unmanagable in the future, wheras ideally I would like to eventually get rid of all singletons from my project.

    I'm still in the process of transferring fom Iteration 2 -> 3 atm so this hasn't been fully implemented, although I see it making the model code, and the qml code more managable, I imagine as the code grows, it would be less managable overtime.

    Final Part

    So what would you consider to be the best practice of setting up communication between the qml C++ interface and the subystems, without having a large negative impact on performance or code design?

    1 Reply Last reply
    0
    • fcarneyF Offline
      fcarneyF Offline
      fcarney
      wrote on last edited by
      #2

      We just create models and use context properties. Or have the QML code request the model from another object via function or property. We generally have an application object that manages the lifetime of the smaller objects.

      C++ is a perfectly valid school of magic.

      1 Reply Last reply
      1

      • Login

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