We have moved to a new Sailfish OS Forum. Please start new discussions there.
1

QQmlEngine rootContext setContextProperty

asked 2019-02-24 17:32:23 +0300

ratijas gravatar image

https://sailfishos.org/develop/docs/libsailfishapp/

Here's missing documentation that supposed to explain how to get QQmlEngine instance, so that app could e.g. register global context property or something.

How to do it, given SailfishApp::main(argc, argv); template?

edit retag flag offensive close delete

Comments

PS Please, do not assume that I'm an expert in Qt.

ratijas ( 2019-02-24 17:40:49 +0300 )edit

Feel free to add it?

tortoisedoc ( 2019-02-24 18:00:52 +0300 )edit

@tortoisedoc well, idk how to do it myself, hence asking a question.

ratijas ( 2019-02-24 18:38:50 +0300 )edit

@ratijas, thanks for the example. I've submitted a PR to add this to the docs: https://github.com/sailfishos/libsailfishapp/pull/39 (comments welcome).

flypig ( 2019-03-13 13:24:13 +0300 )edit

1 Answer

Sort by » oldest newest most voted
2

answered 2019-02-24 20:37:08 +0300

ratijas gravatar image

Here is how it's done manually:

int main(int argc, char *argv[])
{
    QGuiApplication *app = SailfishApp::application(argc, argv);
    QQuickView *view = SailfishApp::createView();

    BookShelfModel model;
    view->engine()->rootContext()->setContextProperty("bookShelf", &model);
    /* any other code involving engine customization */

    view->setSource(SailfishApp::pathToMainQml());
    view->show();
    return app->exec();
}
edit flag offensive delete publish link more
Login/Signup to Answer

Question tools

Follow
4 followers

Stats

Asked: 2019-02-24 17:32:23 +0300

Seen: 877 times

Last updated: Feb 24 '19