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

Revision history [back]

click to hide/show revision 1
initial version

posted 2019-08-13 13:14:35 +0200

QNetworkConfigurationManager and setContextProperty

I need to keep track on the state of connectivity, and wanted to use QNetworkConfigurationManager for that.

In the main c++ I have this (stripped down):

int main(int argc, char *argv[]) {
    QGuiApplication *app = SailfishApp::application(argc, argv);
    QQuickView *view = SailfishApp::createView();
    QNetworkConfigurationManager ncm;
    view->rootContext()->setContextProperty("ncm", &ncm);
    view->setSource(SailfishApp::pathTo("qml/harbour-currencyconverter.qml"));
    view->showFullScreen();
    return app->exec();
}

When I try to use it from QML as in console.log('From ncm:', ncm.isOnline()) it prints TypeError: Property 'isOnline' of object QNetworkConfigurationManager(0xffefeca8) is not a function

I looked at this, but as I see it I'm doing exactly like it and the documentation says - but I have been proven wrong many times ;)