[Qt-qml] Accessing dynamic properties
jamey.hicks at nokia.com
jamey.hicks at nokia.com
Wed Sep 15 13:51:02 CEST 2010
Hi Aaron,
In what way are Qt dynamic properties at in conflict with QML design goals?
QML appears to be a dynamic language. It includes support for Javascript, which is definitely a dynamic language. It seems inconsistent to me that QML would require the complete static type before instantiation. I'm not sure I know what it means when you say "static type" to describe something only known at runtime.
I do have a specific problem in QML I tried to solve using dynamic properties, but before getting into that I'd like to understand what QML is supposed to be.
-Jamey
On Sep 15, 2010, at 12:02 AM, Kennedy Aaron (Nokia-MS-Qt/Brisbane) wrote:
> Hi,
>
> No it doesn't work, and no its not supposed to work. Qt's dynamic
> properties do not fit the QML model very well which relies on knowing the
> complete static type of an object prior to instantiation, and we'd prefer
> not to support them.
>
> Perhaps if you give more details about the actual problem you are trying to
> solve we can think of an alternative way.
>
> Cheers,
>
> Aaron
>
>
> On 15/09/10 2:58 AM, "Dzyubenko Denis (Nokia-MS-Qt/Oslo)"
> <denis.dzyubenko at nokia.com> wrote:
>
>>
>> On 14. sep. 2010, at 18.20, Hicks Jamey (Nokia-NRC/Cambridge) wrote:
>>
>>> How did you pass in the object? If you pass it as a QVariant you need to cast
>>> it to QObject * first to make its slots and properties available.
>>
>> I've created a test app that shows the problem. Maybe someone can tell me if
>> this is supposed to work at all:
>>
>> #include <QtGui>
>> #include <QtDeclarative>
>>
>> class MyItem: public QDeclarativeItem
>> {
>> Q_OBJECT
>> Q_PROPERTY(int bar READ bar WRITE setBar)
>>
>> public:
>> MyItem()
>> : m_bar(69)
>> {
>> setProperty("foo", QVariant::fromValue<int>(42));
>> setProperty("bar", QVariant::fromValue<int>(43));
>> }
>>
>> int m_bar;
>> int bar() const { return m_bar; }
>> void setBar(int value) { m_bar = value; }
>> };
>> QML_DECLARE_TYPE(MyItem);
>>
>> int main(int argc, char **argv)
>> {
>> QApplication app(argc, argv);
>> qmlRegisterType<MyItem>("org.foobar.foo", 1, 0, "MyItem");
>> QDeclarativeView view;
>>
>> view.setSource(QUrl::fromLocalFile("foo.qml"));
>>
>> view.show();
>> return app.exec();
>> }
>>
>> #include "main.moc"
>>
>>
>>
>> and the foo.qml:
>>
>> import Qt 4.7
>> import org.foobar.foo 1.0
>>
>> MyItem {
>> width: 100
>> height: 100
>>
>> MouseArea {
>> anchors.fill: parent
>> onClicked: { console.log("foo =", parent.foo, "; bar =", parent.bar);
>> }
>> }
>> }
>>
>>
>> I get the following output:
>>
>> foo = undefined ; bar = 43
>>
>> Denis.
>>
>>
>> _______________________________________________
>> Qt-qml mailing list
>> Qt-qml at trolltech.com
>> http://lists.trolltech.com/mailman/listinfo/qt-qml
>
More information about the Qt-qml
mailing list