Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
New Developer
bDev
Posts: 40
Registered: ‎12-14-2013
My Device: Playbook

using networkdatausage class

Hi, not sure why the following code is not displaying the network data

 

data.hpp

#include <QtCore/QObject>
#include <bb/device/NetworkDataUsage>

using namespace bb::device;

class Data&colon; public QObject
{
	Q_OBJECT


public:
	Data(QObject *parent = 0);

	quint64 dataReceived();

private:
	NetworkDataUsage networkData;
};

 

 

data.cpp

#include "data.hpp"
#include <bb/device/NetworkDataUsage>

quint64 Data&colon;:dataReceived() {

	networkData.update();

	quint64 received = networkData.bytesReceived();
	return received;
}

 main.cpp

#include "data.hpp"
#include <bb/device/NetworkDataUsage>

Q_DECL_EXPORT int main(int argc, char **argv)
{

       Data netData;
       quint64 val = netData.dataReceived();
                	qDebug() <<"Bytes Received: "<<val;

}

 But in the cosole, it's showing: 


NetworkDataUsage - failed to read network stats
Bytes Received:  0

Developer
simon_hain
Posts: 16,282
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: using networkdatausage class

maybe a permission issue? no permissions listed in the API, but maybe you need one, just as a guess.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
New Developer
bDev
Posts: 40
Registered: ‎12-14-2013
My Device: Playbook

Re: using networkdatausage class

Err.. permission?

wondering what could that permission be?
BlackBerry Development Advisor
MSohm
Posts: 14,753
Registered: ‎07-09-2008
My Device: BlackBerry Passport

Re: using networkdatausage class

Are you specifying a network interface when initializing NetworkDataUsage?  If you use the constructor that doesn't specify a network interface it'll be initialized to an invalid state - no network interface.

 

NetworkDataUsage (QObject *parent)

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
New Developer
bDev
Posts: 40
Registered: ‎12-14-2013
My Device: Playbook

Re: using networkdatausage class

Hi Mark,

 

It would be great if you could provide a demo code showing how to do it. I tried but somehow it seems to be not working.

New Developer
bDev
Posts: 40
Registered: ‎12-14-2013
My Device: Playbook

Re: using networkdatausage class

well this is what i did:

 

inside the body of the constructor of Data class

NetworkDataUsage netInterface;

	networkData = new NetworkDataUsage(netInterface.networkInterfaceName());

 but still same message in the console

BlackBerry Development Advisor
MSohm
Posts: 14,753
Registered: ‎07-09-2008
My Device: BlackBerry Passport

Re: using networkdatausage class

That would just be using the same, default and invalid network interface.  The QNetworkInterface::allInterfaces() and QNetworkInterface::humanReadableName() methods allow you to get a list of the network interfaces.  You can then use one from that list to instantiate NetworkDataUsage.

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker