[SailfishDevel] How to use setContext() or what is recommended?!
Andrey Kozhevnikov
coderusinbox at gmail.com
Wed Nov 13 15:15:15 UTC 2013
#include <QtQuick>
#include <sailfishapp.h>
#include "MyClass.h"
int main(int argc, char *argv[])
{
QGuiApplication *app = SailfishApp::application(argc, argv);
QQuickView *view = SailfishApp::createView();
MyClass *myclass = new MyClass();
view->rootContext()->setContextProperty("myclass", myclass);
view->setSource(SailfishApp::pathTo("qml/main.qml"));
view->showFullScreen();
return app->exec();
}
On 13.11.2013 20:58, Gabriel Boehme wrote:
> 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
More information about the Devel
mailing list