[SailfishDevel] Alpha 2: passing simple properties from

christopher.lamb at thurweb.ch christopher.lamb at thurweb.ch
Sun Aug 4 13:50:31 UTC 2013


@Mario

yes BB10 seems to have a setContextProperty (I found this while  
googling for a Sailfish solution).
http://developer.blackberry.com/cascades/documentation/dev/integrating_cpp_qml/

@Martin

I tried your suggestion before posting my question:

QScopedPointer<QQuickView> view(Sailfish::createView("main.qml"));
view->rootContext()->setContextProperty("platform", platformId);

While my code compiles, when I try and use the property platform in my  
QML I get errors:

file:///opt/sdk/landedsettingsQt5_21/usr/share/landedsettingsQt5_21/main.qml:34: ReferenceError: platform is not  
defined

Chris


Zitat von "Mario Zorz" <mariozorz at gmail.com>:

>  main.cpp to qml
> MIME-Version: 1.0
> Content-Type: text/plain; charset="utf-8"
> Content-Transfer-Encoding: 7bit
>
> Wait, that setContextProperty is still there in Qt 4.8 shipped with
> blackberry 10 as well.
> Sure it was only in the Nokia branch?
>
> Mario
> De: Martin Grimme
> Enviado: 04/08/2013 09:31 a.m.
> Para: christopher.lamb at thurweb.ch
> CC: devel at lists.sailfishos.org
> Asunto: Re: [SailfishDevel] Alpha 2: passing simple properties from
> main.cpp to qml
> Hi,
>
> you don't want to set the context property on the
> QmlApplicationViewer, which was dead Nokia code to target Symbian and
> Harmattan, anyway.
> QmlApplicationViewer was derived from QmlView, where it got the
> rootContext() method from.
>
> With Qt5, QmlView was renamed to QQuickView. And when using the
> functions from sailfishapplication.h, you get a QQuickView*, e.g.:
>
>         QScopedPointer<QQuickView> view(Sailfish::createView("main.qml"));
>         view->rootContext()->setContextProperty("platform", platformId);
>
>
> Martin
>
>
> 2013/8/4, christopher.lamb at thurweb.ch <christopher.lamb at thurweb.ch>:
>> Hi all
>>
>> What is the recommended way to pass simple c++ properties from the
>> main.cpp to the QML part of a project using the Qt 5 Alpha?
>>
>> In the good old days of the first Alpha, I used to do this Harmattan
>> style using
>>
>>      QmlApplicationViewer viewer;
>>      viewer.rootContext()->setContextProperty("platform",  platformId);
>>
>> This would make the c++ property platformId available to my qml code
>> as the property platform.
>>
>> Now with Qt5 / Alpha 2 the QmlApplicationViewer is no longer created.
>>
>> The tutorial linked below suggests that the QmlApplicationViewer files
>> could be ported to Qt5, so I guess I could grab these files from an
>> old Harmattan project and do that.
>>
>> https://qt-project.org/doc/qt-5.0/qtdoc/portingqmlapp.html
>>
>> But somehow that feels like carting old baggage around.
>>
>> Is their a Sailfish native way of doing the same?
>>
>> Thanks
>>
>> Chris
>>
>>
>>
>>
>> _______________________________________________
>> SailfishOS.org Devel mailing list
>>
> _______________________________________________
> SailfishOS.org Devel mailing list
>




More information about the Devel mailing list