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-boun...@lists.sailfishos.org [devel-boun...@lists.sailfishos.org] on behalf of Gabriel Boehme [m.gabrielboe...@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