×
Namespaces

Variants
Actions
(Difference between revisions)

Get System information using Qt

From Nokia Developer Wiki
Jump to: navigation, search
somnathbanik (Talk | contribs)
hamishwillee (Talk | contribs)
m (Text replace - "<code cpp>" to "<code cpp-qt>")
 
(3 intermediate revisions by one user not shown)
Line 1: Line 1:
 
[[Category:Qt Mobility]]
 
[[Category:Qt Mobility]]
{{CodeSnippet
+
{{ArticleMetaData
 
|id=...
 
|id=...
 
|platform=S60 3rd Edition, FP1, FP2<br>S60 5th Edition
 
|platform=S60 3rd Edition, FP1, FP2<br>S60 5th Edition
Line 8: Line 8:
 
|creationdate=March 30, 2010
 
|creationdate=March 30, 2010
 
|keywords= QSystemInfo, QListWidget, QScrollArea
 
|keywords= QSystemInfo, 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]]
 
}}
 
}}
  
Line 23: Line 31:
  
 
==Headers required==
 
==Headers required==
<code cpp>
+
<code cpp-qt>
 
#include <qsysteminfo.h>
 
#include <qsysteminfo.h>
 
</code>
 
</code>
Line 30: Line 38:
 
Modify your '''.pro''' file as follows.
 
Modify your '''.pro''' file as follows.
  
<code cpp>
+
<code cpp-qt>
 
QT += core \
 
QT += core \
 
     gui \
 
     gui \
Line 45: Line 53:
 
==Header file==
 
==Header file==
  
<code cpp>
+
<code cpp-qt>
 
/* GetSystemInfo.h */
 
/* GetSystemInfo.h */
  
Line 84: Line 92:
 
==Source file==
 
==Source file==
  
<code cpp>
+
<code cpp-qt>
 
/* GetStorageInfo.cpp */
 
/* GetStorageInfo.cpp */
  
Line 387: Line 395:
 
* [[Get Storage information using Qt for Symbian]]
 
* [[Get Storage information using 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: QSystemInfo, QListWidget, QScrollArea
Created: Yashu (30 Mar 2010)
Last edited: hamishwillee (11 Oct 2012)

Contents

[edit] Overview

This code example shows how to access system information from the device. Using this code we can get current language, current country code, available language, OS version, Qt lib version, Firmware, and other available features of the device. Code example use QSystemInfo API from QtMobility APIs. Basically the system information API offers access to discover system-related information and capabilities.

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] .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

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

[edit] Source file

/* GetStorageInfo.cpp */
 
 
#include "GetSystemInfo.h"
#include <QListWidget>
#include <QScrollArea>
 
GetSystemInfo::GetSystemInfo(QWidget *parent)
: QMainWindow(parent)
{
setWindowTitle("Get system information");
 
/*The sysInfo becomes a child of the GetDisplayInfo, and will be destroyed when the GetDisplayInfo is deleted */
sysInfo = new QSystemInfo(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);
getSystemInformation();
}
 
void GetSystemInfo::getSystemInformation()
{
QString strInfo;
 
/* get current language of device */
strInfo.append(sysInfo->currentLanguage());
strInfo.prepend("Current language: ");
listWidget->addItem(strInfo);
 
/* get current country code of device */
strInfo.clear();
strInfo.append(sysInfo->currentCountryCode());
strInfo.prepend("Current country code: ");
listWidget->addItem(strInfo);
 
/* get available languages of device */
QStringList langList = sysInfo->availableLanguages();
QString langStr;
 
strInfo.clear();
strInfo.append("Available languages are: ");
listWidget->addItem(strInfo);
 
 
foreach ( QString str, langList )
{
langStr.clear();
langStr.append(" ");
langStr.append(str);
listWidget->addItem(langStr);
}
 
/* get OS version of device */
strInfo.clear();
strInfo.append(sysInfo->version(QSystemInfo::Os));
strInfo.prepend("OS version: ");
listWidget->addItem(strInfo);
 
/* get library version of device */
strInfo.clear();
strInfo.append(sysInfo->version(QSystemInfo::QtCore));
strInfo.prepend("Qt lib version: ");
listWidget->addItem(strInfo);
 
/* get firmware version of device */
strInfo.clear();
strInfo.append(sysInfo->version(QSystemInfo::Firmware));
strInfo.prepend("Firmware version: ");
listWidget->addItem(strInfo);
 
/* get available feature of device */
strInfo.clear();
strInfo.append("Following feature is available on device: ");
listWidget->addItem(strInfo);
 
/* check if bluetooth is available on device */
strInfo.clear();
strInfo.append(" Bluetooth: ");
if(sysInfo->hasFeatureSupported(QSystemInfo::BluetoothFeature))
{
strInfo.append("Yes");
}
else
{
strInfo.append("No");
}
listWidget->addItem(strInfo);
 
/* check if camera is available on device */
strInfo.clear();
strInfo.append(" Camera: ");
if(sysInfo->hasFeatureSupported(QSystemInfo::CameraFeature))
{
strInfo.append("Yes");
}
else
{
strInfo.append("No");
}
listWidget->addItem(strInfo);
 
/* check if FM radio is available on device */
strInfo.clear();
strInfo.append(" FM radio: ");
if(sysInfo->hasFeatureSupported(QSystemInfo::FmradioFeature))
{
strInfo.append("Yes");
}
else
{
strInfo.append("No");
}
listWidget->addItem(strInfo);
 
/* check if infra-red is available on device */
strInfo.clear();
strInfo.append(" Infra Red: ");
if(sysInfo->hasFeatureSupported(QSystemInfo::IrFeature))
{
strInfo.append("Yes");
}
else
{
strInfo.append("No");
}
listWidget->addItem(strInfo);
 
/* check if LED is available on device */
strInfo.clear();
strInfo.append(" LED: ");
if(sysInfo->hasFeatureSupported(QSystemInfo::LedFeature))
{
strInfo.append("Yes");
}
else
{
strInfo.append("No");
}
listWidget->addItem(strInfo);
 
/* check if memory card feature is available on device */
strInfo.clear();
strInfo.append(" Memory card: ");
if(sysInfo->hasFeatureSupported(QSystemInfo::MemcardFeature))
{
strInfo.append("Yes");
}
else
{
strInfo.append("No");
}
listWidget->addItem(strInfo);
 
/* check if USB is available on device */
strInfo.clear();
strInfo.append(" USB: ");
if(sysInfo->hasFeatureSupported(QSystemInfo::UsbFeature))
{
strInfo.append("Yes");
}
else
{
strInfo.append("No");
}
listWidget->addItem(strInfo);
 
/* check if vibration is available on device */
strInfo.clear();
strInfo.append(" Vibration: ");
if(sysInfo->hasFeatureSupported(QSystemInfo::VibFeature))
{
strInfo.append("Yes");
}
else
{
strInfo.append("No");
}
listWidget->addItem(strInfo);
 
/* check if WLAN is available on device */
strInfo.clear();
strInfo.append(" WLAN: ");
if(sysInfo->hasFeatureSupported(QSystemInfo::WlanFeature))
{
strInfo.append("Yes");
}
else
{
strInfo.append("No");
}
listWidget->addItem(strInfo);
 
/* check if SIM feature is available on device */
strInfo.clear();
strInfo.append(" SIM feature: ");
if(sysInfo->hasFeatureSupported(QSystemInfo::SimFeature))
{
strInfo.append("Yes");
}
else
{
strInfo.append("No");
}
listWidget->addItem(strInfo);
 
/* check if GPS is available on device */
strInfo.clear();
strInfo.append(" GPS: ");
if(sysInfo->hasFeatureSupported(QSystemInfo::LocationFeature))
{
strInfo.append("Yes");
}
else
{
strInfo.append("No");
}
listWidget->addItem(strInfo);
 
/* check if Video is available on device */
strInfo.clear();
strInfo.append(" Video: ");
if(sysInfo->hasFeatureSupported(QSystemInfo::VideoOutFeature))
{
strInfo.append("Yes");
}
else
{
strInfo.append("No");
}
listWidget->addItem(strInfo);
 
/* check if Haptics is available on device */
strInfo.clear();
strInfo.append(" Haptics: ");
if(sysInfo->hasFeatureSupported(QSystemInfo::HapticsFeature))
{
strInfo.append("Yes");
}
else
{
strInfo.append("No");
}
listWidget->addItem(strInfo);
}
 
GetSystemInfo::~GetSystemInfo()
{
 
}
 
void GetSystemInfo::setWidgetGeometry(QSize* screenSize)
{
resize(*screenSize);
QRect rect(0,0,screenSize->width(), screenSize->height());
listWidget->setGeometry(rect);
}

[edit] Postconditions

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

System information 1
QtSystemInfoSC1.jpg

System information 2
QtSystemInfoSC2.jpg

QtSystemInfoSC3.jpg

[edit] Download Code Example

[edit] Related articles

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