[SailfishDevel] C++ and QML Integration: SetContextProperty with the latest SailfishOS Templates
Wim de Vries
wsvries at xs4all.nl
Thu Dec 12 13:37:27 UTC 2013
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
On 12/12/2013 02:16 PM, christopher.lamb at thurweb.ch wrote:
> Hi All
>
> what is now the recommended way to SetContextProperty in the main
> function using the latest Sailfish application templates (from thp)?
>
> The default main now looks like:
>
> #include <sailfishapp.h>
>
> int main(int argc, char *argv[])
> {
>
> return SailfishApp::main(argc, argv);
> }
>
> In the days of the old template and sailfishapplication I used to do
> it this way:
>
> #include "sailfishapplication.h"
>
> Q_DECL_EXPORT int main(int argc, char *argv[])
> {
> QScopedPointer<QGuiApplication>
> app(Sailfish::createApplication(argc, argv));
>
> //New Sailfish Alpha 2 /Qt 5 way
> //requires patch to sailfishapplication.cpp from Lucien Xu
> QScopedPointer<QQuickView> view(Sailfish::createView());
> view->rootContext()->setContextProperty("cppproperty", "Hello
> world");
> Sailfish::setView(view.data(), "main.qml");
>
> Sailfish::showView(view.data());
> return app->exec();
> }
>
> Thanks
>
> Chris
>
>
>
> _______________________________________________
> SailfishOS.org Devel mailing list
>
More information about the Devel
mailing list