[Qt-qml] How to think about Attached Properties?
Charley Bay
charleyb123 at gmail.com
Sat Nov 27 02:45:39 CET 2010
I'm implementing "attached properties" on my custom C++ type (exposed to
QML), and am unsure about the "proper" use model:
<http://doc.qt.nokia.com/4.7/qml-extending.html>
For example, I did:
(a) Implement C++ class MyAttachedProperties, derived from QObject
(b) Implement static function and QML_DECLARE_TYPEINFO on C++
MyClassWithAttachedProperties so QML triggers instantiation of the attached
properties object.
The above seems to work fine. My questions:
(1) Logically, should the "state" for MyAttachedProperties simply reside
within the QObject meta-object system (e.g., through the QObject (base)
"property()/setProperty()")? Or, can I have my own "state" in data members
for MyAttachedProperties that I "expose" as properties, or explicitly set as
properties within the QObject (base) meta-object?
(2) In the event I have application-specific types/state in
MyAttachedProperties, what "synchronization hooks" are assumed to be used to
expose that state to QML elements? (For example, to translate
application-specific type state to QVariant values useful to QML elements?)
(3) Are there examples showing use of "attached properties" other than what
is mentioned in the "Birthday" example in the Qt 4.7 docs? (I didn't find
anything else, or anything else on the web ... ?) Specifically, I'd like to
see examples of "recursive grouped" attached properties state like the docs
mention is possible, such as binding a value within QML like "a.b.c.d.e: 42"
Thanks!
--charley
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt.nokia.com/pipermail/qt-qml/attachments/20101126/71f3bc6e/attachment.html
More information about the Qt-qml
mailing list