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

QNetworkConfigurationManager and setContextProperty [answered]

asked 2019-08-13 13:14:35 +0300

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

updated 2019-08-13 13:14:35 +0300

Tanghus gravatar image

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);
    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 ;)

edit retag flag offensive reopen delete

The question has been closed for the following reason "the question is answered, an answer was accepted" by Tanghus
close date 2019-08-13 22:53:40.190925

1 Answer

Sort by » oldest newest most voted

answered 2019-08-13 14:43:04 +0300

coderus gravatar image

isOnline is not Q_INVOKABLE or public slot, it can't be called from qml code

edit flag offensive delete publish link more


Thanks again @coderus. I'll pursue another way. Actually we've been here before. You gave me hints on the same subject. I got the network dialog to open just fine, but the snippet you gave about network status, I couldn't get to work, and the search engines weren't any help. You wrote:

import org.freedesktop.contextkit 1.0

ContextProperty {
    id: networkOnline
    key: 'Network.Online'

Just to see if anything at all happens, I did a console.log('Network context', networkOnline) which in turn printed Can't open property "Network.Online" Sys: "No file" User: "No file".

I might as well be Swahili to me ;)

Tanghus ( 2019-08-13 16:44:36 +0300 )edit

You can check content of /run/state/namespaces

coderus ( 2019-08-13 16:51:56 +0300 )edit

Excellent! Progress :)

ContextProperty {
    id: networkOnline
    key: 'Internet.NetworkState'

Now I tried console.log('Network context', networkOnline.value, networkOnline.subscribed) which gives Network context undefined true. So there's some kind of contact. I have absolutely no idea, what I'm messing with here, so extra hints will be much appeciated :)

Tanghus ( 2019-08-13 17:54:20 +0300 )edit

I can see, I'm not the only one having problems with this ;)


Tanghus ( 2019-08-13 18:06:57 +0300 )edit

Forgot to mention, that I also tried networkOnline.subscribe(). It changed nothing and also returned undefined.

Tanghus ( 2019-08-13 18:32:22 +0300 )edit

Question tools



Asked: 2019-08-13 13:14:35 +0300

Seen: 90 times

Last updated: Aug 13 '19