[SailfishDevel] How to use setContext() or what is recommended?!

Gabriel Boehme m.gabrielboehme at googlemail.com
Wed Nov 13 15:23:13 UTC 2013


Wow, thanks to you and also Andrey!

This is nearly the way I took back in the first Jolla Qt5 SDK, is it
also the recommended way to do that?

Will it have a (bad) influence on the start up times?

Thanks so much! :)

> Hi,
> 
> Yes your setContextProperty() to rootContext is the right approach. Usually I do something like this:
> 
>     QScopedPointer<QGuiApplication> app(Sailfish::createApplication(argc, argv));
>     QScopedPointer<QQuickView> view(Sailfish::createView());
>     MyClass data;
>     view->rootContext()->setContextProperty("myObject", &data);
>     Sailfish::setView(view.data(), "qrc:/main.qml");
> 
> ________________________________________
> From: devel-bounces at lists.sailfishos.org [devel-bounces at lists.sailfishos.org] on behalf of Gabriel Boehme [m.gabrielboehme at googlemail.com]
> Sent: Wednesday, November 13, 2013 4:58 PM
> To: Sailfish OS Developers
> Subject: [SailfishDevel] How to use setContext() or what is recommended?!
> 
> Hi sailors,
> 
> in the very first (Qt4 version) of the SDK I ported an easy application,
> that is using a list model. To connect the list model and also my main
> logic stuff I used the setContextProperty() method. In the first Qt5 SDK
> version I had to work a bit around that (created a view from
> Sailfish::createView() and used the views
> data().rootContext()->setContextProperty() methods.
> 
> But now in the latest version I'm not quite sure about, how to do that?
> 
> Or better: What is the recommended way to connect QML UI with C++ logic
> and add a model for a view? I'm a bit confused, because coming from
> Python/PySide I always used it that way with QDeclarativeView and get a
> bit lost with Qt5 and QQuickView and QQuickApplication and all this
> stuff, that changed also between 5.0 and 5.1, doesn't it? :-/
> 
> Would be great to get some advice!
> 
> Thank you very much!
> 
> _______________________________________________
> SailfishOS.org Devel mailing list
> _______________________________________________
> SailfishOS.org Devel mailing list




More information about the Devel mailing list