Get device information using Qt
Template:Abstract Template:ArticleNeedsUpdate Template:ArticleMetaData
Headers required[edit | edit source]
- include <qsysteminfo.h>
.pro file[edit | edit source]
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
Header file[edit | edit source]
/* GetDeviceInfo.h */
- ifndef GETDEVICEINFO_H
- define GETDEVICEINFO_H
- include <QtGui/QMainWindow>
- include <qsysteminfo.h>
QTM_USE_NAMESPACE;
class QListWidget;
class QScrollArea;
class GetDeviceInfo : public QMainWindow
{
Q_OBJECT
public:
GetDeviceInfo(QWidget *parent = 0);
~GetDeviceInfo();
private:
void resizeEvent (QResizeEvent* event);
void setWidgetGeometry(QSize* screenSize);
void getDeviceInformation();
private:
QSystemDeviceInfo* sysInfo;
QListWidget *listWidget;
QScrollArea *scrollArea;
};
- endif // GETDEVICEINFO_H
Source file[edit | edit source]
/* GetDeviceInfo.cpp */
- include "GetDeviceInfo.h"
- include <QListWidget>
- include <QScrollArea>
- include <QResizeEvent>
GetDeviceInfo::GetDeviceInfo(QWidget *parent)
: QMainWindow(parent)
{
setWindowTitle("Get device information");
sysInfo = new QSystemDeviceInfo(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);
getDeviceInformation();
}
GetDeviceInfo::~GetDeviceInfo()
{
}
void GetDeviceInfo::resizeEvent (QResizeEvent* event)
{
QSize widgetSize = event->size();
setWidgetGeometry(&widgetSize);
QMainWindow::resizeEvent(event);
}
void GetDeviceInfo::setWidgetGeometry(QSize* screenSize)
{
resize(*screenSize);
QRect rect(0,0,screenSize->width(), screenSize->height());
listWidget->setGeometry(rect);
}
void GetDeviceInfo::getDeviceInformation()
{
QString strInfo;
/* get IMEI of device */
strInfo.append("IMEI: " + sysInfo->imei());
listWidget->addItem(strInfo);
/* get IMSI of device */
strInfo.clear();
strInfo.append("IMSI: " + sysInfo->imsi());
listWidget->addItem(strInfo);
/* get manufacturer of device */
strInfo.clear();
strInfo.append("Manufacturer: " + sysInfo->manufacturer());
listWidget->addItem(strInfo);
/* get model number of device */
strInfo.clear();
strInfo.append("Model: " + sysInfo->model());
listWidget->addItem(strInfo);
/* get product name of device */
strInfo.clear();
strInfo.append("Product name: " + sysInfo->productName());
listWidget->addItem(strInfo);
/* get battery level of device*/
strInfo.clear();
strInfo.setNum(sysInfo->batteryLevel());
strInfo.prepend("Battery level: ");
strInfo.append("%");
listWidget->addItem(strInfo);
/* check if device locked */
strInfo.clear();
strInfo.append("Device locked: ");
if(sysInfo->isDeviceLocked())
strInfo.append("Yes");
else
strInfo.append("No");
listWidget->addItem(strInfo);
/* get battery status of device*/
strInfo.clear();
strInfo.append("Battery status: ");
switch(sysInfo->batteryStatus ())
{
case QSystemDeviceInfo::BatteryNormal:
{
strInfo.append("Normal");
break;
}
case QSystemDeviceInfo::BatteryLow:
{
strInfo.append("Low");
break;
}
case QSystemDeviceInfo::BatteryVeryLow:
{
strInfo.append("Very Low");
break;
}
case QSystemDeviceInfo::BatteryCritical:
{
strInfo.append("Critical");
break;
}
case QSystemDeviceInfo::NoBatteryLevel:
default:
{
strInfo.append("Battery level not found");
break;
}
}
listWidget->addItem(strInfo);
/* get current power state of device*/
strInfo.clear();
strInfo.append("Current power state: ");
switch(sysInfo->currentPowerState())
{
case QSystemDeviceInfo::BatteryPower:
{
strInfo.append("Battery power");
break;
}
case QSystemDeviceInfo::WallPower:
{
strInfo.append("Wall power");
break;
}
case QSystemDeviceInfo::WallPowerChargingBattery:
{
strInfo.append("Wall power charging battery");
break;
}
case QSystemDeviceInfo::UnknownPower:
default:
{
strInfo.append("Power error!!");
break;
}
}
listWidget->addItem(strInfo);
/* get SIM status of device*/
strInfo.clear();
strInfo.append("SIM status: ");
switch(sysInfo->simStatus())
{
case QSystemDeviceInfo::SingleSimAvailable:
{
strInfo.append("Single sim available");
break;
}
case QSystemDeviceInfo::DualSimAvailable:
{
strInfo.append("Dual sim available");
break;
}
case QSystemDeviceInfo::SimLocked:
{
strInfo.append("Sim locked");
break;
}
case QSystemDeviceInfo::SimNotAvailable:
{
strInfo.append("Sim not available");
break;
}
default:
{
strInfo.append("Error in getting status!!");
break;
}
}
listWidget->addItem(strInfo);
/* get current profile of device*/
strInfo.clear();
strInfo.append("Current profile: ");
switch(sysInfo->currentProfile())
{
case QSystemDeviceInfo::NormalProfile:
{
strInfo.append("General");
break;
}
case QSystemDeviceInfo::SilentProfile:
{
strInfo.append("Silent");
break;
}
case QSystemDeviceInfo::VibProfile:
{
strInfo.append("Vibrate");
break;
}
case QSystemDeviceInfo::LoudProfile:
{
strInfo.append("Loud");
break;
}
case QSystemDeviceInfo::OfflineProfile:
{
strInfo.append("Offline ");
break;
}
case QSystemDeviceInfo::CustomProfile:
{
strInfo.append("Custom profile");
break;
}
case QSystemDeviceInfo::PowersaveProfile:
{
strInfo.append("Powersave ");
break;
}
case QSystemDeviceInfo::UnknownProfile:
default:
{
strInfo.append("Error in profile!!");
break;
}
}
listWidget->addItem(strInfo);
/* get supported input methods of device*/
strInfo.clear();
strInfo.append("Supported input methods are: ");
listWidget->addItem(strInfo);
QSystemDeviceInfo::InputMethodFlags inputMethods = sysInfo->inputMethodType();
strInfo.clear();
strInfo.append(" Keys: ");
if((inputMethods & QSystemDeviceInfo::Keys))
{
strInfo.append("Yes");
}
else
{
strInfo.append("No");
}
listWidget->addItem(strInfo);
strInfo.clear();
strInfo.append(" Keypad: ");
if((inputMethods & QSystemDeviceInfo::Keypad))
{
strInfo.append("Yes");
}
else
{
strInfo.append("No");
}
listWidget->addItem(strInfo);
strInfo.clear();
strInfo.append(" Keyboard: ");
if((inputMethods & QSystemDeviceInfo::Keyboard))
{
strInfo.append("Yes");
}
else
{
strInfo.append("No");
}
listWidget->addItem(strInfo);
strInfo.clear();
strInfo.append(" Single touch: ");
if((inputMethods & QSystemDeviceInfo::SingleTouch))
{
strInfo.append("Yes");
}
else
{
strInfo.append("No");
}
listWidget->addItem(strInfo);
strInfo.clear();
strInfo.append(" Multi touch: ");
if((inputMethods & QSystemDeviceInfo::MultiTouch))
{
strInfo.append("Yes");
}
else
{
strInfo.append("No");
}
listWidget->addItem(strInfo);
strInfo.clear();
strInfo.append(" Mouse: ");
if((inputMethods & QSystemDeviceInfo::Mouse))
{
strInfo.append("Yes");
}
else
{
strInfo.append("No");
}
listWidget->addItem(strInfo);
}
Post-conditions[edit | edit source]
The code snippet is expected to read device information from device and show it on screen.
Device information 1 |
Device information 2 |
Download Code Example[edit | edit source]
- Working Code Example is available to download from here.