[SailfishDevel] best way to set QML properties from within C++ in Sailfish?
Wim de Vries
wsvries at xs4all.nl
Thu Dec 12 13:48:32 UTC 2013
On 12/12/2013 02:28 PM, Wim de Vries wrote:
> Thanks.
>
> On 12/12/2013 01:44 PM, Robin Burchell wrote:
>> On 12 Dec 2013, at 13:42, Wim de Vries <wsvries at xs4all.nl
>> <mailto:wsvries at xs4all.nl>> wrote:
>>> I need to set many properties in QML elements from within C++.
>>
>> You may find it easier to expose these properties *from* C++ to QML,
>> using a singleton type (for example)
>>
>> http://qt-project.org/doc/qt-5.0/qtqml/qtqml-cppintegration-definetypes.html#registering-singleton-objects-with-a-singleton-type
>>
> Yes, I have to control many property values.
>>> QT documentation:
>>> QQmlEngine <http://qt-project.org/doc/qt-5.0/qtqml/qqmlengine.html> engine;
>>> QQmlComponent <http://qt-project.org/doc/qt-5.0/qtqml/qqmlcomponent.html> component(&engine, "MyItem.qml");
>>> QObject <http://qt-project.org/doc/qt-5.0/qtcore/qobject.html> *object= component.create();
>>> qDebug <http://qt-project.org/doc/qt-5.0/qtcore/qtglobal.html#qDebug>()<< "Property value:" << QQmlProperty <http://qt-project.org/doc/qt-5.0/qtqml/qqmlproperty.html>::read(object, "someNumber").toInt();
>>> QQmlProperty <http://qt-project.org/doc/qt-5.0/qtqml/qqmlproperty.html>::write(object, "someNumber", 5000)
>>>
>>> Still in Sailfish we only have a QQuickView*, no
>>> QQmlEngine/QQmlComponent.
>>> How do I get their from QQuickView?
>>
>> http://qt-project.org/doc/qt-5.1/qtquick/qquickview.html#engine
> I'll try this one indeed.
That doesn't work. I need the object (whatever type of object that may
be) returned by component.create.
>>
>>> Also,
>>> Can I get to all Pages (even if not active) and their nested childs
>>> via the above mentioned QObject* ?
>>
>> Not easily, AFAIK.
>>
>>
>> _______________________________________________
>> SailfishOS.org Devel mailing list
>
>
>
> _______________________________________________
> SailfishOS.org Devel mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.sailfishos.org/pipermail/devel/attachments/20131212/6b8f570d/attachment.html>
More information about the Devel
mailing list