Access property set with setProperty from QML

relgukxilef

I've got a subclass of QObject and use setProperty to add dynamic properties to it in C++.

Now I want to use them in QML. I would have expected to be able to access them like properties defined with Q_PROPERTY but that only yields undefined.

folibis

It is currently not possible. As a possible workaround you can expose from your C++ object to QML some helper function to get the value of a dynamic property:

TestObject::TestObject(QObject *parent) : QObject(parent)
{
    setProperty("test","testvalue");
}

QVariant TestObject::getDynamicProperty(const QString &name)
{
    return property(name.toLatin1());
}

and so you will be able to get its value from QML:

TestObject {
    Component.onCompleted: console.log(getDynamicProperty("test"));
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

jsp:setproperty property=“*” not set all properties

From Dev

Qt / QML set property from c++ class for GridView

From Dev

Qt / QML set property from c++ class for GridView

From Dev

Access ObservableCollection items from property set

From Dev

QML: Set Property of Nested ListElement

From Dev

QML Access object property by property name string

From Dev

QML , How to Access Element from Another qml

From Dev

How to access a component bound to a property in QML

From Dev

QML Binding with Javascript array access to QObject Property

From Dev

How to set property type of qml signal?

From Dev

QML: Conditionally set different properties of a property group

From Dev

How to set property type of qml signal?

From Dev

access qml element from javascript

From Dev

Access QList<T> from qml

From Dev

Read property from QML singleton with C++

From Dev

How to prevent Laravel from loading full set of data on object property access after already querying a restricted set

From Dev

QT/QML c++ Program crash on access a QList from QML

From Dev

How to bind a property to a singleton object property from QML

From Dev

QML not registering property change from C++ property

From Dev

How to access C++ enum from QML?

From Dev

QML TableView access model properties from delegate

From Dev

Access QML WebView from C++

From Dev

Is it possible to access QML anchors from C++?

From Dev

Access to Javascript array elements from ListModel in QML

From Dev

How to access C++ enum from QML?

From Dev

How to access a qml ListElement from c++

From Dev

How to set QML properties from C++

From Dev

setProperty value from requested getParameter

From Dev

'Error 380: Could not set the RowSource property. Invalid Property value' for Excel user form to import data from Access to Excel

Related Related

  1. 1

    jsp:setproperty property=“*” not set all properties

  2. 2

    Qt / QML set property from c++ class for GridView

  3. 3

    Qt / QML set property from c++ class for GridView

  4. 4

    Access ObservableCollection items from property set

  5. 5

    QML: Set Property of Nested ListElement

  6. 6

    QML Access object property by property name string

  7. 7

    QML , How to Access Element from Another qml

  8. 8

    How to access a component bound to a property in QML

  9. 9

    QML Binding with Javascript array access to QObject Property

  10. 10

    How to set property type of qml signal?

  11. 11

    QML: Conditionally set different properties of a property group

  12. 12

    How to set property type of qml signal?

  13. 13

    access qml element from javascript

  14. 14

    Access QList<T> from qml

  15. 15

    Read property from QML singleton with C++

  16. 16

    How to prevent Laravel from loading full set of data on object property access after already querying a restricted set

  17. 17

    QT/QML c++ Program crash on access a QList from QML

  18. 18

    How to bind a property to a singleton object property from QML

  19. 19

    QML not registering property change from C++ property

  20. 20

    How to access C++ enum from QML?

  21. 21

    QML TableView access model properties from delegate

  22. 22

    Access QML WebView from C++

  23. 23

    Is it possible to access QML anchors from C++?

  24. 24

    Access to Javascript array elements from ListModel in QML

  25. 25

    How to access C++ enum from QML?

  26. 26

    How to access a qml ListElement from c++

  27. 27

    How to set QML properties from C++

  28. 28

    setProperty value from requested getParameter

  29. 29

    'Error 380: Could not set the RowSource property. Invalid Property value' for Excel user form to import data from Access to Excel

HotTag

Archive