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. Exposing C++ classes to qml via context is good or bad?
Qt 6.11 is out! See what's new in the release blog

Exposing C++ classes to qml via context is good or bad?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 490 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.
  • D Offline
    D Offline
    diredko
    wrote on last edited by
    #1

    Hi all, I'm working on an application and I want to use a controller-based architecture according to which I have a lot of classes (derived from QObject) and they are being exposed to qml so that it can bind to their properites, subscribe to signals and call functions. Now to expose controllers I'm using QQmlContext and setContextProperty, but I' m not sure whether this is a good approach.
    Could someone suggest an alternative approach? I would appreciate any comments :)

    Thanks in advance!

    E 1 Reply Last reply
    0
    • D diredko

      Hi all, I'm working on an application and I want to use a controller-based architecture according to which I have a lot of classes (derived from QObject) and they are being exposed to qml so that it can bind to their properites, subscribe to signals and call functions. Now to expose controllers I'm using QQmlContext and setContextProperty, but I' m not sure whether this is a good approach.
      Could someone suggest an alternative approach? I would appreciate any comments :)

      Thanks in advance!

      E Offline
      E Offline
      Eeli K
      wrote on last edited by
      #2

      @diredko Technically speaking you're not exposing classes but objects. Another approach is to expose classes by registering them and then create objects in QML. Personally I don't see anything wrong with your approach, except that there are lots of global objects to be accessed in QML. As long as it's easy to maintain I don't see a reason to change it. But more experienced programmers may have other opinions.

      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