Best way to export Q_PROPERTY in a wrapper?
-
I have a class
A
derived fromQObject
, which has some properties and may be moved to another thread. I have another classAWrapper
wrapping this object, and this class is exposed to QML. What is the most succinct way to "export" properties inA
toAWrapper
?Currently I have a few options:
- Duplicate the members in the wrapper, and use
Q_PROPERTY(member MEMBER m_member NOTIFY memberChanged)
, and connect the changed signal toA::setMember
. - Call setter/getter directly:
Q_PROPERTY(member READ member WRITE setMember)
where the setter/getter directly callA
's setter/getter - Like 2, but instead of calling setter/getter directly, make new signals to connect to
A
's setter/getter.
I used 1 and 2 in my project, but I like none of these solutions. (1) duplicates data, (2) is potentially unsafe, and (3) involves a lot of boilerplate. Is there a better way to export properties in a wrapper class?
- Duplicate the members in the wrapper, and use
-
Hi and welcome to devnet,
Why do you need that wrapper ? A being a QObject you can directly use it in QML.
-
Hi and welcome to devnet,
Why do you need that wrapper ? A being a QObject you can directly use it in QML.
-
By instantiating in QML do you mean create the objects there or pass them as property context ?
-
By instantiating in QML do you mean create the objects there or pass them as property context ?
-
So you would like to achieve something similar to the QtQuick Threading example ?
-
So you would like to achieve something similar to the QtQuick Threading example ?
-
So you would like to achieve something similar to the QtQuick Threading example ?