qnetworkwatcher is a qt/qml service that listen to the network status and inform for any changes.
It give you a simple access to the network state (up/down) which adaptater is up and shortcut for wifi, eth and wcdma in both cpp and qml code.
- simple, only add the directory and pri file to your project
- easy to use, only one class as a service (singleton)
- give you the network status live
- shortcut for the main interface
- fully integrated with qml
Some example
You can use Qnetworkwatcher from both Qt and Qml
Registering the service
// from the main process QScopedPointerapp(SailfishApp::application(argc, argv)); QScopedPointer view(SailfishApp::createView()); qnetworkwatcher::init(view->rootContext());
from Qml
var haswifi = networkwatcher.wifi; ... Connections { target: networkwatcher onNetworkChanged : { console.log("Network status changed") notification.publish(); } }
from QT
bool haswifi = QNWI.getWifi();
Install
Install is really simple and only require to add the lib to your project. Steps assume you use the default names and locations
- Copy the src/qnetworkwatcher directory into your src directory
- Edit the project's .pro file and include qnetworkwatcher.pri reference
From Github or inside the .tgz you will find a full qtcreator project.
Download
You can get QNetworkwatcher from the github repository
Editing .pro file
Here the .pro file for the sample application
TARGET = harbour-test_qnetworkwatcher CONFIG += sailfishapp include(src/qnetworkwatcher/qnetworkwatcher.pri) SOURCES += src/harbour-test_qnetworkwatcher.cpp DISTFILES += qml/harbour-test_qnetworkwatcher.qml \ qml/cover/*.qml \ qml/pages/*.qml \ rpm/harbour-test_qnetworkwatcher.changes \ rpm/harbour-test_qnetworkwatcher.spec \ rpm/harbour-test_qnetworkwatcher.yaml \ harbour-test_qnetworkwatcher.desktop SAILFISHAPP_ICONS = 86x86 108x108 128x128 256x256