×
Namespaces

Variants
Actions
(Difference between revisions)

Get Network information using Qt

From Nokia Developer Wiki
Jump to: navigation, search
Yashu (Talk | contribs)
m
hamishwillee (Talk | contribs)
m (Text replace - "<code cpp>" to "<code cpp-qt>")
 
(9 intermediate revisions by 5 users not shown)
Line 1: Line 1:
{{CodeSnippet
+
[[Category:Qt Mobility]]
 +
{{ArticleMetaData
 
|id=...
 
|id=...
 
|platform=S60 3rd Edition, FP1, FP2<br>S60 5th Edition
 
|platform=S60 3rd Edition, FP1, FP2<br>S60 5th Edition
 
|devices= Nokia 5800 and Nokia N97.
 
|devices= Nokia 5800 and Nokia N97.
|category=Qt for Symbian
+
|category=Qt
 
|subcategory= Qt Mobility API
 
|subcategory= Qt Mobility API
 
|creationdate=March 30, 2010
 
|creationdate=March 30, 2010
 
|keywords= QSystemNetworkInfo, QListWidget, QScrollArea
 
|keywords= QSystemNetworkInfo, QListWidget, QScrollArea
 +
 +
|sourcecode= <!-- Link to example source code (e.g. [[Media:The Code Example ZIP.zip]]) -->
 +
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
 +
|sdk=<!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Nokia Qt SDK 1.1]) -->
 +
|devicecompatability=<!-- Compatible devices (e.g.: All* (must have GPS) ) -->
 +
|signing=<!-- Empty or one of Self-Signed, DevCert, Manufacturer -->
 +
|capabilities=<!-- Capabilities required (e.g. Location, NetworkServices.) -->
 +
|author=[[User:Yashu]]
 
}}
 
}}
  
 
==Overview==
 
==Overview==
  
This code example shows how to access network information from the system. For example to get current MCC, current MNC, home MCC, home MNC location area code, network name, network signal strength, network status and MAC address  of the device. Code example use QSystemNetworkInfo API from QtMobility APIs.
+
{{Abstract|visible=true|This code example shows how to access network information from the system. For example to get current MCC, current MNC, home MCC, home MNC location area code, network name, network signal strength, network status and MAC address  of the device. Code example use {{Icode|QSystemNetworkInfo}} API from {{Icode|QtMobility}} APIs.}}
  
This snippet requires ReadDeviceData capabilities. Self-signing is not possible, a [[Developer certificate]] is needed to sign application for testing.
+
This snippet requires {{Icode|ReadDeviceData}} capabilities. '''Self-signing''' is not possible, a [[Developer certificate]] is needed to sign application for testing.
  
 
==Prerequisite==
 
==Prerequisite==
Line 22: Line 31:
  
 
==Headers required==
 
==Headers required==
<code cpp>
+
<code cpp-qt>
 
#include <qsysteminfo.h>
 
#include <qsysteminfo.h>
 
</code>
 
</code>
 +
 +
== Capabilities required ==
 +
* [[ReadDeviceData]]
  
 
== .pro file==
 
== .pro file==
Modify your .pro file as follows.
+
Modify your''' .pro''' file as follows.
  
<code cpp>
+
<code cpp-qt>
 
QT += core \
 
QT += core \
 
     gui \
 
     gui \
Line 44: Line 56:
 
==Header file==
 
==Header file==
  
<code cpp>
+
<code cpp-qt>
 
/* GetNetworkInfo.h */
 
/* GetNetworkInfo.h */
  
Line 80: Line 92:
  
 
==Source file==
 
==Source file==
<code cpp>
+
<code cpp-qt>
 
/* GetNetworkInfo.cpp */
 
/* GetNetworkInfo.cpp */
 
#include "GetNetworkInfo.h"
 
#include "GetNetworkInfo.h"
Line 136: Line 148:
 
 
 
/* get Cell Id */
 
/* get Cell Id */
/*strInfo.append("Cell ID: " + sysInfo->cellId());  
+
strInfo.setNum(sysInfo->cellId());
listWidget->addItem(strInfo);*/
+
        strInfo.prepend("Cell ID: ");
 +
        listWidget->addItem(strInfo);
 
 
 
/* get current MCC */
 
/* get current MCC */
Line 240: Line 253:
 
* [[Get System information using Qt for Symbian]]
 
* [[Get System information using Qt for Symbian]]
  
[[Category:Qt]][[Category:Qt for Symbian]][[Category:Code Examples]]
+
[[Category:Code Examples]][[Category:MeeGo Harmattan]] [[Category:Symbian]]

Latest revision as of 04:23, 11 October 2012

Article Metadata
Tested with
Devices(s): Nokia 5800 and Nokia N97.
Compatibility
Platform(s): S60 3rd Edition, FP1, FP2
S60 5th Edition
Symbian
Article
Keywords: QSystemNetworkInfo, QListWidget, QScrollArea
Created: Yashu (30 Mar 2010)
Last edited: hamishwillee (11 Oct 2012)

Contents

[edit] Overview

This code example shows how to access network information from the system. For example to get current MCC, current MNC, home MCC, home MNC location area code, network name, network signal strength, network status and MAC address of the device. Code example use QSystemNetworkInfo API from QtMobility APIs.

This snippet requires ReadDeviceData capabilities. Self-signing is not possible, a Developer certificate is needed to sign application for testing.

[edit] Prerequisite


[edit] Headers required

#include <qsysteminfo.h>

[edit] Capabilities required

[edit] .pro file

Modify your .pro file as follows.

QT += core \
gui \
network
INCLUDEPATH += d:/qtmobility/src/systeminfo
INCLUDEPATH += D:/QtMobility/src/global
 
CONFIG += mobility
MOBILITY = systeminfo
symbian:TARGET.CAPABILITY = ReadDeviceData


[edit] Header file

/* GetNetworkInfo.h */
 
#ifndef GETNETWORKINFO_H
#define GETNETWORKINFO_H
 
#include <QtGui/QMainWindow>
#include <qsysteminfo.h>
QTM_USE_NAMESPACE;
 
class QListWidget;
class QScrollArea;
 
class GetNetworkInfo : public QMainWindow
{
Q_OBJECT
 
public:
GetNetworkInfo(QWidget *parent = 0);
~GetNetworkInfo();
 
private:
void resizeEvent (QResizeEvent* event);
void setWidgetGeometry(QSize* screenSize);
void getNetworkInformation();
 
private:
QSystemNetworkInfo* sysInfo;
QListWidget *listWidget;
QScrollArea *scrollArea;
};
 
#endif // GETNETWORKINFO_H

[edit] Source file

/* GetNetworkInfo.cpp */
#include "GetNetworkInfo.h"
#include <QListWidget>
#include <QScrollArea>
#include <QResizeEvent>
 
GetNetworkInfo::GetNetworkInfo(QWidget *parent)
: QMainWindow(parent)
{
setWindowTitle("Get network information");
 
/*The sysInfo becomes a child of the GetDisplayInfo, and will be destroyed when the GetDisplayInfo is deleted */
sysInfo = new QSystemNetworkInfo(this);
 
/* To show items in list view */
listWidget = new QListWidget();
listWidget->setObjectName(QString::fromUtf8("listWidget"));
 
/* To make UI scrollable */
scrollArea = new QScrollArea();
setWidgetGeometry(&(size()));
 
/* scrollArea takes ownership of the listWidget, so no need to delete it */
scrollArea->setWidget(listWidget);
scrollArea->setAlignment(Qt::AlignLeft);
scrollArea->setWidgetResizable(true);
 
/* QMainWindow takes ownership of the scrollArea, so no need to delete it */
setCentralWidget(scrollArea);
getNetworkInformation();
}
 
GetNetworkInfo::~GetNetworkInfo()
{
}
 
void GetNetworkInfo::resizeEvent (QResizeEvent* event)
{
QSize widgetSize = event->size();
setWidgetGeometry(&widgetSize);
QMainWindow::resizeEvent(event);
}
 
void GetNetworkInfo::setWidgetGeometry(QSize* screenSize)
{
resize(*screenSize);
QRect rect(0,0,screenSize->width(), screenSize->height());
listWidget->setGeometry(rect);
}
 
void GetNetworkInfo::getNetworkInformation()
{
QString strInfo;
 
/* get Cell Id */
strInfo.setNum(sysInfo->cellId());
strInfo.prepend("Cell ID: ");
listWidget->addItem(strInfo);
 
/* get current MCC */
strInfo.clear();
strInfo.append("Current MCC: " + sysInfo->currentMobileCountryCode());
listWidget->addItem(strInfo);
 
/* get current MNC */
strInfo.clear();
strInfo.append("Current MNC: " + sysInfo->currentMobileNetworkCode());
listWidget->addItem(strInfo);
 
/* get home MCC */
strInfo.clear();
strInfo.append("home MCC: " + sysInfo->homeMobileCountryCode());
listWidget->addItem(strInfo);
 
/* get home MNC */
strInfo.clear();
strInfo.append("home MNC: " + sysInfo->homeMobileNetworkCode());
listWidget->addItem(strInfo);
 
/* get location area code */
strInfo.clear();
strInfo.setNum(sysInfo->locationAreaCode());
strInfo.prepend("Location area code: ");
listWidget->addItem(strInfo);
 
/* get network name */
strInfo.clear();
strInfo.append("Network name: " + sysInfo->networkName(QSystemNetworkInfo::GsmMode));
listWidget->addItem(strInfo);
 
/* get network signal strength*/
strInfo.clear();
strInfo.setNum(sysInfo->networkSignalStrength(QSystemNetworkInfo::GsmMode));
strInfo.prepend("Network signal strength: ");
strInfo.append("%");
listWidget->addItem(strInfo);
 
/* get network status */
strInfo.clear();
strInfo.append("Network status: ");
 
switch(sysInfo->networkStatus(QSystemNetworkInfo::GsmMode))
{
case QSystemNetworkInfo::Roaming:
strInfo.append("On Roaming network.");
break;
case QSystemNetworkInfo::Denied:
strInfo.append("Network access denied.");
break;
case QSystemNetworkInfo::Home Network:
strInfo.append("On Home Network");
break;
case QSystemNetworkInfo::Connected:
strInfo.append("Connected to network.");
break;
case QSystemNetworkInfo::Busy:
strInfo.append("Network is busy.");
break;
case QSystemNetworkInfo::Searching:
strInfo.append("Searching for or connecting with the network.");
break;
case QSystemNetworkInfo::EmergencyOnly:
strInfo.append("Emergency calls only.");
break;
case QSystemNetworkInfo::NoNetworkAvailable:
strInfo.append("There is no network available.");
break;
case QSystemNetworkInfo::UndefinedStatus:
Default:
strInfo.append("There is no network device, or error.");
break;
}
 
listWidget->addItem(strInfo);
 
/* get IMSI of device */
strInfo.clear();
strInfo.append("MAC address: " + sysInfo->macAddress(QSystemNetworkInfo::GsmMode));
listWidget->addItem(strInfo);
}

[edit] Postconditions

The code snippet is expected to read network information from device and show it on screen.

QtNetworkInfo.jpg

[edit] Download Code Example

[edit] Related articles

This page was last modified on 11 October 2012, at 04:23.
120 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×