[SailfishDevel] C++ and QML Integration: SetContextProperty with the latest SailfishOS Templates

christopher.lamb at thurweb.ch christopher.lamb at thurweb.ch
Thu Dec 12 14:04:41 UTC 2013


Hi Wim

Thanks, that works! (except that you probably did not mean "view" to  
be 2nd param of setContextProperty).

So taking your example I can do:

int main(int argc, char *argv[])
{
     bool cppproperty = true;

     QGuiApplication *app = SailfishApp::application(argc, argv);
     QQuickView *view = SailfishApp::createView();
     view->rootContext()->setContextProperty("cppproperty",  cppproperty);
     view->setSource(SailfishApp::pathTo("qml/SetContextPropertyQt5.qml"));
     view->showFullScreen();
     app->exec();

}

But combining your approach, and the QScopedPointers, this also works:

int main(int argc, char *argv[])
{
     bool simulator = true;

     QScopedPointer<QGuiApplication> app(SailfishApp::application(argc, argv));
     QScopedPointer<QQuickView> view(SailfishApp::createView());
     view->rootContext()->setContextProperty("cppproperty",  cppproperty);
     view->setSource(SailfishApp::pathTo("qml/SetContextPropertyQt5.qml"));
     view->show();
     view->showFullScreen();
     app->exec();

}

So which of the 2 approaches is better, and why?

Grüsse

Chris


Zitat von "Wim de Vries" <wsvries at xs4all.nl>:

> Hi Cristopher,
> I got this answer some time ago:
>
>     QGuiApplication *app = SailfishApp::application(argc, argv);
>     QQuickView *view = SailfishApp::createView();
>     view->rootContext()->setContextProperty("cppproperty", view);
> view->setSource(SailfishApp::pathTo("qml/main.qml"));
>     view->showFullScreen();
>     app->exec();
>
> r
> wim
>




More information about the Devel mailing list