×
Namespaces

Variants
Actions
(Difference between revisions)

Working with QSystemNetworkInfo - System Information API - Part 2

From Nokia Developer Wiki
Jump to: navigation, search
avisheksomani (Talk | contribs)
(Source file)
avisheksomani (Talk | contribs)
(Source file)
Line 156: Line 156:
 
{
 
{
 
return "Undefined";
 
return "Undefined";
                          break;
+
                        break;
 
}
 
}
 
case QSystemNetworkInfo::NoNetworkAvailable:
 
case QSystemNetworkInfo::NoNetworkAvailable:
 
{
 
{
 
return "Unavailable";
 
return "Unavailable";
break;
+
                        break;
 
}
 
}
 
case QSystemNetworkInfo::EmergencyOnly:
 
case QSystemNetworkInfo::EmergencyOnly:
 
{
 
{
 
return "Emergency";
 
return "Emergency";
break;
+
                        break;
 
}
 
}
 
case QSystemNetworkInfo::Searching:
 
case QSystemNetworkInfo::Searching:
 
{
 
{
 
return "Searching";
 
return "Searching";
break;
+
                        break;
 
}
 
}
 
case QSystemNetworkInfo::Busy:
 
case QSystemNetworkInfo::Busy:
 
{
 
{
 
return "Busy";
 
return "Busy";
break;
+
                        break;
 
}
 
}
 
case QSystemNetworkInfo::Connected:
 
case QSystemNetworkInfo::Connected:
 
{
 
{
 
return "Connected";
 
return "Connected";
break;
+
                        break;
 
}
 
}
 
case QSystemNetworkInfo::HomeNetwork:
 
case QSystemNetworkInfo::HomeNetwork:
 
{
 
{
 
return "On home n/w";
 
return "On home n/w";
break;
+
                        break;
 
}
 
}
 
case QSystemNetworkInfo::Denied:
 
case QSystemNetworkInfo::Denied:
 
{
 
{
 
return "Access denied";
 
return "Access denied";
break;
+
                        break;
 
}
 
}
 
case QSystemNetworkInfo::Roaming:
 
case QSystemNetworkInfo::Roaming:
 
{
 
{
 
return "On Roaming";
 
return "On Roaming";
break;
+
                        break;
 
}
 
}
 
default:
 
default:
 
{
 
{
 
return "Error";
 
return "Error";
break;
+
                        break;
 
}
 
}
 
}
 
}

Revision as of 16:59, 12 October 2010

ID Creation date 15-March-2010
Platform S60 3rd Edition, FP1, FP2

S60 5th Edition

Tested on devices Nokia 5800 xPressMusic
Category Qt for Symbian Subcategory Qt Mobility API


Keywords (APIs, classes, methods, functions): QSystemNetworkInfo, QString, QButton, QLabel, QComboBox


Tip.pngTip: 


Contents

Overview =

This is a part 2 of the QSystemNetworkInfo API which is a part of the System Information API from Qt Mobility project.

What is covered in QSystemNetworkInfo API Part 2

  • It is a part of the System Information API.
  • This article covers information about
    • MAC address of the specified network mode
    • Network status of the specified network mode


Capabilities required

  • ReadDeviceData


UI design (.ui file)

QSystemNetworkInfo-2 UI.PNG


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 SYSTEMNETWORKINFO2_H
#define SYSTEMNETWORKINFO2_H
 
#include <QtGui/QWidget>
#include "ui_SystemNetworkInfo2.h"
#include <qsysteminfo.h>
 
using namespace QtMobility;
class SystemNetworkInfo2 : public QWidget
{
Q_OBJECT
 
public:
SystemNetworkInfo2(QWidget *parent = 0);
~SystemNetworkInfo2();
 
public slots:
void displayNetworkInfo(int aIndex);
void resetAllFields();
 
private:
QString getNetworkStatusString(QSystemNetworkInfo::NetworkStatus aIndex);
 
private:
Ui::SystemNetworkInfo2 ui;
QSystemNetworkInfo* networkInfo;
};
 
#endif // SYSTEMNETWORKINFO2_H


Source file

#include "SystemNetworkInfo2.h"
 
SystemNetworkInfo2::SystemNetworkInfo2(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()));
}
 
SystemNetworkInfo2::~SystemNetworkInfo2()
{
delete networkInfo;
networkInfo = NULL;
}
 
void SystemNetworkInfo2::displayNetworkInfo(int aIndex)
{
if(! aIndex)
{
resetAllFields();
return;
}
 
QString macAddress = networkInfo->macAddress((QSystemNetworkInfo::NetworkMode)aIndex);
if(! macAddress.length())
{
ui.macLabel->setText("Not applicable");
}
else
{
ui.macLabel->setText(macAddress);
}
ui.statusLabel->setText(getNetworkStatusString(
networkInfo->networkStatus(
(QSystemNetworkInfo::NetworkMode)aIndex)));
}
 
QString SystemNetworkInfo2::getNetworkStatusString(QSystemNetworkInfo::NetworkStatus aIndex)
{
switch(aIndex)
{
case QSystemNetworkInfo::UndefinedStatus:
{
return "Undefined";
break;
}
case QSystemNetworkInfo::NoNetworkAvailable:
{
return "Unavailable";
break;
}
case QSystemNetworkInfo::EmergencyOnly:
{
return "Emergency";
break;
}
case QSystemNetworkInfo::Searching:
{
return "Searching";
break;
}
case QSystemNetworkInfo::Busy:
{
return "Busy";
break;
}
case QSystemNetworkInfo::Connected:
{
return "Connected";
break;
}
case QSystemNetworkInfo::HomeNetwork:
{
return "On home n/w";
break;
}
case QSystemNetworkInfo::Denied:
{
return "Access denied";
break;
}
case QSystemNetworkInfo::Roaming:
{
return "On Roaming";
break;
}
default:
{
return "Error";
break;
}
}
}
 
void SystemNetworkInfo2::resetAllFields()
{
ui.macLabel->clear();
ui.statusLabel->clear();
ui.comboBox->setCurrentIndex(0);
}

Output

QSystemNetworkInfo-2 device.jpg


Useful functions

  • QString macAddress(QSystemNetworkInfo::NetworkMode mode);
  • QSystemNetworkInfo::NetworkStatus networkStatus(QSystemNetworkInfo::NetworkMode mode);


Keywords

Headers

  • #include <qsysteminfo.h>

Classes

  • QSystemNetworkInfo
  • QString
  • QButton
  • QLabel
  • QComboBox


Example Application


Related articles

Reference links

155 page views in the last 30 days.
×