×
Namespaces

Variants
Actions
(Difference between revisions)

Get Storage 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= QSystemStorageInfo, QListWidget, QScrollArea
 
|keywords= QSystemStorageInfo, 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>
 
/* GetStorageInfo.h */
 
/* GetStorageInfo.h */
 
#ifndef GETSTORAGEINFO_H
 
#ifndef GETSTORAGEINFO_H
Line 85: Line 93:
 
==Source file==
 
==Source file==
  
<code cpp>
+
<code cpp-qt>
 
/* GetStorageInfo.cpp */
 
/* GetStorageInfo.cpp */
 
#include "GetStorageInfo.h"
 
#include "GetStorageInfo.h"
Line 283: Line 291:
 
* [[Get System information using Qt for Symbian]]
 
* [[Get System 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: QSystemStorageInfo, QListWidget, QScrollArea
Created: Yashu (30 Mar 2010)
Last edited: hamishwillee (11 Oct 2012)

Contents

[edit] Overview

This code example shows how to access storage information from the device. For example to get name of available drives, available space on each drive, total space on each drive and type of drive of the device. Code example use QSystemStorageInfo 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] .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

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

[edit] Source file

/* GetStorageInfo.cpp */
#include "GetStorageInfo.h"
#include <QListWidget>
#include <QScrollArea>
#include <QResizeEvent>
 
GetStorageInfo::GetStorageInfo(QWidget *parent)
: QMainWindow(parent)
{
setWindowTitle("Get storage information");
 
/*The sysInfo becomes a child of the GetDisplayInfo, and will be destroyed when the GetDisplayInfo is deleted */
sysInfo = new QSystemStorageInfo(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);
getStorageInformation();
}
 
GetStorageInfo::~GetStorageInfo()
{
 
}
 
void GetStorageInfo::resizeEvent (QResizeEvent* event)
{
QSize widgetSize = event->size();
setWidgetGeometry(&widgetSize);
QMainWindow::resizeEvent(event);
}
 
void GetStorageInfo::setWidgetGeometry(QSize* screenSize)
{
resize(*screenSize);
QRect rect(0,0,screenSize->width(), screenSize->height());
listWidget->setGeometry(rect);
}
 
void GetStorageInfo::getStorageInformation()
{
QString strInfo;
//* qlonglong defined in 4.2 same as qint64
 
qlonglong diskSpace;
 
/*get logical drives */
QStringList driveList = sysInfo->logicalDrives();
 
strInfo.append("Drives information: ") ;
listWidget->addItem(strInfo);
 
foreach ( QString str, driveList )
{
strInfo.clear();
strInfo.append(" Drive name: " + str);
listWidget->addItem(strInfo);
 
/* get available space on drive. */
diskSpace = sysInfo->availableDiskSpace(str);
 
strInfo.clear();
 
if(diskSpace > 1000000)
{
diskSpace /= 1000000;
strInfo.setNum(diskSpace);
strInfo.prepend(" Available space: ");
strInfo.append("MB");
 
}
else if(diskSpace > 1000)
{
diskSpace /= 1000;
strInfo.setNum(diskSpace);
strInfo.prepend(" Available space: ");
strInfo.append("KB");
 
}
else
{
strInfo.setNum(diskSpace);
strInfo.prepend(" Available space: ");
strInfo.append("Bytes");
}
 
listWidget->addItem(strInfo);
 
/* get total space on drive */
diskSpace = sysInfo->totalDiskSpace(str);
 
strInfo.clear();
 
if(diskSpace > 1000000)
{
diskSpace /= 1000000;
strInfo.setNum(diskSpace);
strInfo.prepend(" Total space: ");
strInfo.append("MB");
 
}
else if(diskSpace > 1000)
{
diskSpace /= 1000;
strInfo.setNum(diskSpace);
strInfo.prepend(" Total space: ");
strInfo.append("KB");
 
}
else
{
strInfo.setNum(diskSpace);
strInfo.prepend(" Total space: ");
strInfo.append("Bytes");
}
 
listWidget->addItem(strInfo);
 
strInfo.clear();
strInfo.append(" Type of drives: ");
 
/* get type of drive */
switch(sysInfo->typeForDrive(str))
{
case QSystemStorageInfo::InternalDrive:
{
strInfo.append("InternalDrive");
break;
}
case QSystemStorageInfo::RemovableDrive:
{
strInfo.append("RemovableDrive");
break;
}
case QSystemStorageInfo::RemoteDrive:
{
strInfo.append("RemoteDrive");
break;
}
case QSystemStorageInfo::CdromDrive:
{
strInfo.append("CdromDrive");
break;
}
case QSystemStorageInfo::NoDrive:
default:
{
strInfo.append("NoDrive available");
break;
}
}
 
listWidget->addItem(strInfo);
 
strInfo.clear();
strInfo.append(" ");
listWidget->addItem(strInfo);
}
}


[edit] Postconditions

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


Storage information 1
QtStorageInfoSC1.jpg

Storage information 2
QtStorageInfoSC2.jpg

[edit] Download Code Example

[edit] Related articles

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