Question on QDeclarativeItem attribute/properties
-
wrote on 12 Dec 2010, 16:59 last edited by
See this code snip,
@
Text {
id: text2
text: qsTr("Hello devnet")
}
@If I now try to obtain the properties of this via this code:
@
QDeclarativeItem childitem = qobject_cast<QDeclarativeItem>(myobject);
const QMetaObject *metaObject = childitem->metaObject();
for(int j = 0; j < metaObject->propertyCount(); ++j)
@and in the loop if I display all the properties, I find 2 issues that I'm seeking an answer to ...
- How can I get the id, "text2"
- The property "text" just shows "Hello devnet", how can I know if qsTr was used or not
-
wrote on 12 Dec 2010, 17:31 last edited by
My understanding is that in QML the id and objectName are separate and in your case you might be able to access it via objectName.
You can explicitly give an objectName like this
@Text {
id: text2
objectName: "objText2"
}@ -
wrote on 12 Dec 2010, 22:34 last edited by
Any property can be bound to arbitrary JavaScript. Are you asking to get the binding data or perhaps the source code for the binding?
-
wrote on 13 Dec 2010, 00:33 last edited by
[quote author="chetankjain" date="1292173184"]1. How can I get the id, "text2"[/quote]
The id is not currently accessible from C++ (it is not an actual property in the meta object system). As QtK pointed out, you can use objectName, though generally it is discouraged to work with the internals of a QML app from C++ in this way (see the warning "here":http://doc.qt.nokia.com/4.7-snapshot/qtbinding.html#locating-child-objects)
[quote author="chetankjain" date="1292173184"]2. The property "text" just shows "Hello devnet", how can I know if qsTr was used or not[/quote]
This is also not currently possible to get from the meta object system (which only gives access to the value of the property), unless the property is of type "QDeclarativeScriptString":http://doc.qt.nokia.com/4.7-snapshot/qdeclarativescriptstring.html.
Can you say any more about what you would like to use these two pieces of information for? Note that the (private) QML debug/dom API allows access to both of these things for Creator.
Regards,
Michael -
wrote on 14 Dec 2010, 06:12 last edited by
[quote author="QtK" date="1292175104"]My understanding is that in QML the id and objectName are separate and in your case you might be able to access it via objectName.
[/quote]
No I do not want to use the objectName, I will explain my scenario below ... -
wrote on 14 Dec 2010, 06:17 last edited by
[quote author="mbrasser" date="1292200382"]though generally it is discouraged to work with the internals of a QML app from C++ in this way (see the warning "here":http://doc.qt.nokia.com/4.7-snapshot/qtbinding.html#locating-child-objects)
...This is also not currently possible to get from the meta object system (which only gives access to the value of the property), unless the property is of type "QDeclarativeScriptString":http://doc.qt.nokia.com/4.7-snapshot/qdeclarativescriptstring.html.
Can you say any more about what you would like to use these two pieces of information for? Note that the (private) QML debug/dom API allows access to both of these things for Creator.
[/quote]I'm writing a test application to do some specific tests/checks on a QML based application and wanted this info from the QML object tree/composition .. my access is read only and will never modify the QML.
Thanks for the links. :)
I will chk further and revert ... -
wrote on 14 Dec 2010, 06:46 last edited by
[quote author="chetankjain" date="1292307467"]I'm writing a test application to do some specific tests/checks on a QML based application and wanted this info from the QML object tree/composition .. my access is read only and will never modify the QML.[/quote]
For reference, here is an earlier discussion on the mailing list regarding testing/id access:
http://lists.trolltech.com/pipermail/qt-qml/2010-November/001532.htmlRegards,
Michael -
wrote on 14 Dec 2010, 08:21 last edited by
thanks Micheal, this is very helpful, :)
I'll explore qmlunit next, probably relook at my approach -
wrote on 14 Dec 2010, 23:56 last edited by
One more link of interest in regards to testing QML:
http://bugreports.qt.nokia.com/browse/QTBUG-15801 (QML testing requirements)
1/9