[SailfishDevel] Detect network state & react on it

Slava Monich slava.monich at jolla.com
Sat Oct 8 10:02:38 UTC 2016

Hi Dylan,

 From QML, the easiest way is probably to monitor 
/run/state/providers/connman/Internet/NetworkState and 
/run/state/providers/connman/Internet/NetworkType with ContextProperty 
object. Google for "qml contextkit contextproperty" to find some 
examples. That way, statefs monitors connman state for you and you 
monitor statefs.

You can achieve the same result by directly monitoring the connman state 
over D-Bus. Then libconnman-qt is your friend. It's a C++ library with a 
QML plugin (MeeGo.Connman). That requires a bit more code but takes 
statefs out of the picture.

There are also Qt network configuration APIs but those are even more 
complicated and not all of those might work the way you would expect 
them to work. But this is the most platform-independent API in case if 
that is important for you (probably not). Internally it also talks to 

Connection selector has a D-Bus API which is easy enough to figure out 
with dbus-monitor. However it's not an official API and it's more or 
less guaranteed to change over time and break your app. Think twice 
before starting to use it.


On 08/10/16 11:59, Dylan Van Assche wrote:
> Hi Sailors,
> For my app Sailfinder I have received a bug report about the network 
> connection. When switching between mobile data & WiFi the app misbehaves.
> I want to detect the current network state to avoid thsi problem. I 
> thought of several possibilities:
>  *
>     Ping everytime to my website before doing other requests
>     (expensive, better not).
>   * Use MCE module which expose the network states in a file (that's
>     what I found on the sailfishos.org website, no more extra
>     information). This option is the one I want to try :)
>  *
>     ...
> And if network isn't available I want to show the network connection 
> dialog but I haven't find any information about it. Can someone help 
> me with it? If possible, in a Harbour way since Sailfinder is also 
> available in the Jolla Store.
> Kind regards,
> Dylan Van Assche

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.sailfishos.org/pipermail/devel/attachments/20161008/8d6a8320/attachment.html>

More information about the Devel mailing list