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. Expose QJsonObject as QProperty

Expose QJsonObject as QProperty

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

    Hi everyone,

    I have a class that is a QML_ELEMENT like

    //file.hpp
    class DropBox :public QObject
    {
        Q_OBJECT
        Q_PROPERTY(QJsonObject  amountJson READ getAmountJson  NOTIFY amountJsonChanged)
        QML_ELEMENT
       QML_SINGLETON
    ...
    

    When using it as singleton in QML as

    //File.qml
    jsob:(Node_Conection.state)?DropBox.amountJson:{}
    

    This works but if I run the qmllint it returns

    Warning: /../../BoxMenu.qml:45:53: Type "QJsonObject" of property "amountJson" not found. This is likely due to a missing dependency entry or a type not being exposed declaratively. [unresolved-type]
                jsob:(Node_Conection.state)?DropBox.amountJson:{}
    

    So what is the best practice to expose a QJsonObject property to QML from C++.

    Another question,

    If using the object not as a singleton but like

    //file.hpp
    class DropBox :public QObject
    {
        Q_OBJECT
        Q_PROPERTY(QJsonObject  amountJson READ getAmountJson  NOTIFY amountJsonChanged)
        QML_ELEMENT
    ...
    

    And using the class in a QAbstractListModel

    like

    /file.hpp
    class BoxModel : public QAbstractListModel
    {
        Q_OBJECT
        Q_PROPERTY(int count READ count NOTIFY countChanged)
        QML_ELEMENT
    ...
    QList<DropBox*> boxes;
    

    In the qml delegate I normally write

    //Delegate.qml
    Rectangle
    {
        id:root
        required property var amountJson;
    

    So the delegate can get the property from the C++ model and object.

    Is that the correct way to define a QJsonObject variable in qml? like using variable type 'var'?

    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