Working with QSystemNetworkInfo - System Information API - Part 1
hamishwillee
(Talk | contribs) m (Hamishwillee - Bot update - Add ArticleMetaData) |
hamishwillee
(Talk | contribs) m (Text replace - "<code cpp>" to "<code cpp-qt>") |
||
| Line 79: | Line 79: | ||
= Project configuration file (.Pro file) = | = Project configuration file (.Pro file) = | ||
* Add the Qt Mobility project configuration option in the .Pro file as shown below | * Add the Qt Mobility project configuration option in the .Pro file as shown below | ||
| − | <code cpp> | + | <code cpp-qt> |
CONFIG += mobility | CONFIG += mobility | ||
MOBILITY += systeminfo | MOBILITY += systeminfo | ||
| Line 86: | Line 86: | ||
* Add required capability in .pro file as shown below: | * Add required capability in .pro file as shown below: | ||
| − | <code cpp> | + | <code cpp-qt> |
symbian:TARGET.CAPABILITY = ReadDeviceData | symbian:TARGET.CAPABILITY = ReadDeviceData | ||
</code> | </code> | ||
| Line 92: | Line 92: | ||
= Implementing QSystemNetworkInfo API = | = Implementing QSystemNetworkInfo API = | ||
* QSystemNetworkInfo API is a part of the QtMobility namespace. So declare the QtMobility namespace as shown below: | * QSystemNetworkInfo API is a part of the QtMobility namespace. So declare the QtMobility namespace as shown below: | ||
| − | <code cpp> | + | <code cpp-qt> |
using namespace QtMobility; | using namespace QtMobility; | ||
</code> | </code> | ||
== Header file== | == Header file== | ||
| − | <code cpp> | + | <code cpp-qt> |
#ifndef SYSTEMNETWORKINFO_H | #ifndef SYSTEMNETWORKINFO_H | ||
#define SYSTEMNETWORKINFO_H | #define SYSTEMNETWORKINFO_H | ||
| Line 127: | Line 127: | ||
== Source file == | == Source file == | ||
| − | <code cpp> | + | <code cpp-qt> |
#include "SystemNetworkInfo.h" | #include "SystemNetworkInfo.h" | ||
Revision as of 04:23, 11 October 2012
Article Metadata
Code Example
Source file: Media:SystemNetworkInfo.zip
Article
Created: kiran10182
(15 Mar 2010)
Last edited: hamishwillee
(11 Oct 2012)
| ID | Creation date | 15-March-2010 | |
| Platform | S60 3rd Edition, FP1, FP2
S60 5th Edition |
Tested on devices | Nokia 5800 xPressMusic |
| Category | Qt | Subcategory | Qt Mobility API |
| Keywords (APIs, classes, methods, functions): QSystemNetworkInfo, QString, QButton, QLabel, QComboBox |
Tip:
- Please read this article before moving forward: Archived:Setting up environment for Qt Mobility API
- Setup Carbide.c++ IDE as explained in this article: Working with Carbide.c++ IDE for Qt Mobility APIs
Contents |
Overview
This is a part 1 of the QSystemNetworkInfo API which is a part of the System Information API from Qt Mobility project. The part 2 of this article can be read from here
What is covered in QSystemNetworkInfo API Part 1
- It is a part of the System Information API.
- This article covers information about
- Cell ID of the network
- Mobile Country code
- Mobile Network code
- Home Mobile Country code
- Home Mobile Network code
- Location Area code
- Network name
- Network Signal strength
Capabilities required
- ReadDeviceData
UI design (.ui file)
Project configuration file (.Pro file)
- Add the Qt Mobility project configuration option in the .Pro file as shown below
CONFIG += mobility
MOBILITY += systeminfo
- Add required capability in .pro file as shown below:
symbian:TARGET.CAPABILITY = ReadDeviceData
Implementing QSystemNetworkInfo API
- QSystemNetworkInfo API is a part of the QtMobility namespace. So declare the QtMobility namespace as shown below:
using namespace QtMobility;
Header file
#ifndef SYSTEMNETWORKINFO_H
#define SYSTEMNETWORKINFO_H
#include <QtGui/QWidget>
#include "ui_SystemNetworkInfo.h"
#include <qsysteminfo.h>
using namespace QtMobility;
class SystemNetworkInfo : public QWidget
{
Q_OBJECT
public:
SystemNetworkInfo(QWidget *parent = 0);
~SystemNetworkInfo();
public slots:
void displayNetworkInfo(int aIndex);
void resetAllFields();
private:
Ui::SystemNetworkInfo ui;
QSystemNetworkInfo* networkInfo;
};
#endif // SYSTEMNETWORKINFO_H
Source file
#include "SystemNetworkInfo.h"
SystemNetworkInfo::SystemNetworkInfo(QWidget *parent)
: QWidget(parent), networkInfo(NULL)
{
ui.setupUi(this);
networkInfo = new QSystemNetworkInfo();
QObject::connect(ui.comboBox,
SIGNAL(currentIndexChanged(int)),
this,
SLOT(displayNetworkInfo(int)));
QObject::connect(ui.resetButton,
SIGNAL(clicked()),
this,
SLOT(resetAllFields()));
}
SystemNetworkInfo::~SystemNetworkInfo()
{
delete networkInfo;
networkInfo = NULL;
}
void SystemNetworkInfo::displayNetworkInfo(int aIndex)
{
if(! aIndex)
{
ui.resultLabel->clear();
return;
}
QString result;
switch(aIndex)
{
case 1:
{
result = QString::number(networkInfo->cellId());
break;
}
case 2:
{
result = networkInfo->currentMobileCountryCode();
break;
}
case 3:
{
result = networkInfo->currentMobileNetworkCode();
break;
}
case 4:
{
result = networkInfo->homeMobileCountryCode();
break;
}
case 5:
{
result = networkInfo->homeMobileNetworkCode();
break;
}
case 6:
{
result = QString::number(networkInfo->locationAreaCode());
break;
}
case 7:
{
result = networkInfo->networkName(QSystemNetworkInfo::GsmMode);
break;
}
case 8:
{
result = QString::number(networkInfo->networkSignalStrength(
QSystemNetworkInfo::GsmMode));
break;
}
default:
{
break;
}
}
if(! result.length())
{
result = ("Not available");
}
ui.resultLabel->setText(result);
}
void SystemNetworkInfo::resetAllFields()
{
ui.resultLabel->clear();
ui.comboBox->setCurrentIndex(0);
}
Output
Useful functions
- int cellId ();
- QString currentMobileCountryCode ();
- QString currentMobileNetworkCode ();
- QString homeMobileCountryCode ();
- QString homeMobileNetworkCode ();
- int locationAreaCode ();
- QString networkName ( QSystemNetworkInfo::NetworkMode mode );
- int networkSignalStrength ( QSystemNetworkInfo::NetworkMode mode );
Keywords
Headers
- #include <qsysteminfo.h>
Classes
- QSystemNetworkInfo
- QString
- QButton
- QLabel
- QComboBox
Example Application
- A working example application is available to download from here: QSystemNetworkInfo part1.zip
Related articles
- Getting started with Qt Mobility APIs
- Archived:Setting up environment for Qt Mobility API
- Working with Carbide.c++ IDE for Qt Mobility APIs
- Working with QSystemInfo - System Information API - Part 1
- Working with QSystemInfo - System Information API - Part 2
- Working with QSystemDeviceInfo - System Information API - Part 1
- Working with QSystemStorageInfo - System Information API
- Working with QSystemDisplayInfo - System Information API
- Working with QSystemNetworkInfo - System Information API - Part 2


