API Documentation

Documentation for developing SailfishOS applications

NetworkDataCounter Class


The NetworkDataCounter class monitors network data usage. More...

Header: #include <mdm-networkdatacounter.h>

Public Types

class Update
enum NetworkType { MobileDataHome, MobileDataRoaming, Wlan }


Public Functions

NetworkDataCounter(QObject *parent = 0)
bool active() const
void resetCounter(const QString &servicePath)
void setActive(bool active)
void setUpdateAccuracy(int updateAccuracy)
void setUpdateInterval(int updateInterval)
int updateAccuracy() const
int updateInterval() const


void activeChanged()
void counterUpdate(const Sailfish::Mdm::NetworkDataCounter::Update &update)
void updateAccuracyChanged()
void updateIntervalChanged()

Detailed Description

The NetworkDataCounter class monitors network data usage.

To use this class, clients must add the following to their qmake project:

 CONFIG += link_pkgconfig
 PKGCONFIG += sailfishmdm

and then #include <mdm-networkdatacounter.h>.

The counterUpdate() signal is emitted whenever an update of network data traffic is available.

Example of usage:

 #include <mdm-networkdatacounter.h>

 void queryNetworkDataUsage(QObject *parent)
     Sailfish::Mdm::NetworkDataCounter *counter = new Sailfish::Mdm::NetworkDataCounter(parent);
     QObject::connect(counter, &Sailfish::Mdm::NetworkDataCounter::counterUpdate, [](const Sailfish::Mdm::NetworkDataCounter::Update &update) {
         qInfo() << "Service:" << update.servicePath;
         qInfo() << "    Sent:" << update.bytesSent << "bytes";
         qInfo() << "    Received:" << update.bytesReceived << "bytes";
         qInfo() << "    Time online:" << update.timeOnline << "seconds";

Member Type Documentation

enum NetworkDataCounter::NetworkType

Describes the network types for which data counters are provided.

Sailfish::Mdm::NetworkDataCounter::MobileDataHome0Mobile data on the home network.
Sailfish::Mdm::NetworkDataCounter::MobileDataRoaming1Mobile data when roaming outside of the home network.
Sailfish::Mdm::NetworkDataCounter::Wlan2WLAN network data.

Property Documentation

active : bool

This property holds true if the counter is active and able to provide updates.

Access functions:

bool active() const
void setActive(bool active)

Notifier signal:

void activeChanged()

updateAccuracy : int

This property holds the accuracy threshold for updates, in kilobytes.

Updates are provided when data traffic changes exceeds this accuracy threshold and the period specified by updateInterval has passed. A low threshold can result in excessive updates that impact performance; it is recommended to set a minimum value of 10kB, or or preferably 1MB.

The default value is 1024kB.

Access functions:

int updateAccuracy() const
void setUpdateAccuracy(int updateAccuracy)

Notifier signal:

void updateAccuracyChanged()

See also updateInterval.

updateInterval : int

This property holds how often updates should be provided, in seconds.

Note that updates are only provided when available. If there is no current network traffic then updates will not be provided.

The default value is 60 seconds.

Access functions:

int updateInterval() const
void setUpdateInterval(int updateInterval)

Notifier signal:

void updateIntervalChanged()

See also updateAccuracy.

Member Function Documentation

NetworkDataCounter::NetworkDataCounter(QObject *parent = 0)

Constructs a NetworkDataCounter with the given parent.


Destroys the NetworkDataCounter.

[signal] void NetworkDataCounter::counterUpdate(const Sailfish::Mdm::NetworkDataCounter::Update &update)

Provides an update of network data statistics.

This is provided when active is true and an update of network data traffic is available. Updates are provided according to the current updateInterval and updateAccuracy.

void NetworkDataCounter::resetCounter(const QString &servicePath)

Resets the counter located at the specified servicePath.

See also Update::servicePath.

We use cookies to improve your user experience and to help us to develop our services. By continuing to browse the site, you approve of our use of cookies.