Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Exposing a dynamic set of properties to Qml
Forum Updated to NodeBB v4.3 + New Features

Exposing a dynamic set of properties to Qml

Scheduled Pinned Locked Moved General and Desktop
qmlproperty
1 Posts 1 Posters 1.3k 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.
  • S Offline
    S Offline
    Smatcher
    wrote on last edited by
    #1

    Hello !

    I'm a trying to do the following with Qml :
    My project is an application with a Qml interface around some non-Qt modules (loaded at runtime).
    The application and the modules communicate through PropertyContainers which are dictionaries of abstract data (the equivalent of a QVariantMap but with a different implementation).
    I want to expose these dictionaries to Qml, without writing C++ code specific to the keys in these dictionaries (new modules and qml interfaces must be developed without rebuilding the application).

    My first implementation relies on QAbstractListModel. I can attach any of these PropertyContainers to the model and a Qml ListView will display a simple property editor. This implementation has some limitations: it only works for Qml Items meant to use a model (Repeater, ListView) and it doesn't allow binding.

    Ideally I would like to have each dictionary entry available as a property from Qml.
    For example a PropertyContainer with the following properties:

    • text = "Hello World"
    • color = "red"
    • width = 100

    Would be wrapped in a "props" QObject which can be accessed from Qml like this

    Rectangle {
        color: props.color
        width: props.width
        TextField {
            text: props.text
        }
    }
    

    Since using QObject's dynamic properties with the function setProperty() doesn't expose the properties to Qml. I am contemplating writing a wrapper QObject class implementing its own setters/getters and using QMetaObjectBuilder to generate a per instance metaObject listing all the dictionary keys as properties.

    Building my own metaObject seems like overkill, risky and prone to cause a lot of problems when updating Qt so I would like to know a few things first.

    • Is there a simpler way to do what I'm trying to do?
    • Why is QMetaObjectBuilder not part of the public API? Is it really a bad idea to write code using this class?
    • Why is it that dynamic properties aren't available from QML? If I'm not mistaken they seem to be available from QScript. Will this change at some point?
    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