[SailfishDevel] C++ information class in QML Re: GPS not turned off if app exits without stopping the GPS

David Greaves david.greaves at jolla.com
Tue Jan 14 00:12:41 UTC 2014

On 13/01/14 23:01, Marcel wrote:
> Hi all,
> Sorry to be slightly offtoppic, but a small question on this: what would be 
> the best practice then if I would need the position in QML and in C++, or in 
> two different pages in QML? Shouldn't I use two PositionSources? I have this 
> problem for my app if I want to show the position in the app cover...

If you have an object which is an information source like this then I declare it
as an object in QML:

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

    PositionSource* ps = new PositionSource;
    view->rootContext()->setContextProperty("PositionSource", ps);


    return app->exec();

Now any of your QML pages/covers/objects can access PositionSource.slot() or
PositionSource.property (see Q_PROPERTY ) or connect to PositionSource.signal()s


More information about the Devel mailing list