Working with QSystemStorageInfo - System Information API
Article Metadata
Code Example
Source file: Media:SystemStorageInfo.zip
Tested with
Devices(s): Nokia 5800 xPressMusic
Compatibility
Platform(s): S60 3rd Edition, FP1, FP2
Platform Security
Signing Required: Self-Signed
Capabilities: None
Article
Keywords: QSystemStorageInfo, QString, QStringList, QButton, QLabel, QComboBox
Created: kiran10182
(10 Mar 2010)
Last edited: hamishwillee
(11 Oct 2012)
Contents |
Overview
This article shows how to use QSystemStorageInfo API which is a part of the System Information API from Qt Mobility project.
What is covered in QSystemStorageInfo API
- It is a part of the System Information API.
- This article covers information about
- Available drives of the device
- Available disc space of the particular drive
- Total disc space of the particular drive
- Type of the particular drive
Capabilities required
- None
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
Implementing QSystemStorageInfo API
- QSystemStorageInfo API is a part of the QtMobility namespace. So declare the QtMobility namespace as shown below:
using namespace QtMobility;
Header file
#ifndef SYSTEMSTORAGEINFO_H
#define SYSTEMSTORAGEINFO_H
#include <QtGui/QWidget>
#include "ui_SystemStorageInfo.h"
#include <qsysteminfo.h>
using namespace QtMobility;
class SystemStorageInfo : public QWidget
{
Q_OBJECT
public:
SystemStorageInfo(QWidget *parent = 0);
~SystemStorageInfo();
public slots:
void listLogicalDrives();
void listDriveInformation(int aDriveIndex);
void resetAllFields();
private:
Ui::SystemStorageInfo ui;
QSystemStorageInfo* storageInfo;
};
#endif // SYSTEMSTORAGEINFO_H
Source file
#include "SystemStorageInfo.h"
SystemStorageInfo::SystemStorageInfo(QWidget *parent)
: QWidget(parent), storageInfo(NULL)
{
ui.setupUi(this);
storageInfo = new QSystemStorageInfo();
QObject::connect(ui.driveComboBox,
SIGNAL(currentIndexChanged(int)),
this,
SLOT(listDriveInformation(int)));
QObject::connect(ui.storageInfoButton,
SIGNAL(clicked()),
this,
SLOT(listLogicalDrives()));
QObject::connect(ui.resetButton,
SIGNAL(clicked()),
this,
SLOT(resetAllFields()));
}
SystemStorageInfo::~SystemStorageInfo()
{
delete storageInfo;
}
void SystemStorageInfo::listLogicalDrives()
{
if(ui.driveComboBox->count() > 1)
{
//this has been called previously and combo box contains data already
ui.driveComboBox->showPopup();
return;
}
QStringList list = storageInfo->logicalDrives();
ui.driveComboBox->addItems(list);
ui.driveComboBox->showPopup();
}
void SystemStorageInfo::listDriveInformation(int aDriveIndex)
{
if(aDriveIndex == 0)
{
resetAllFields();
return;
}
// Set available disc space label
QString textValue = ui.driveComboBox->itemText(aDriveIndex);
qlonglong availableSpace = storageInfo->availableDiskSpace(textValue);
QString str = QString::number(availableSpace);
ui.availabelDiscSpaceLabel->setText(str);
// Set total disc space label
qlonglong totalSpace = storageInfo->totalDiskSpace(textValue);
str = QString::number(totalSpace);
ui.totalDiscSpaceLabel->setText(str);
// Set drive type label
QString labelValue;
QSystemStorageInfo::DriveType drvType = storageInfo->typeForDrive(textValue);
switch(drvType)
{
case QSystemStorageInfo::NoDrive:
{
labelValue = ("No drive");
break;
}
case QSystemStorageInfo::InternalDrive:
{
labelValue = ("Internal Drive");
break;
}
case QSystemStorageInfo::RemovableDrive:
{
labelValue = ("Removable Drive");
break;
}
case QSystemStorageInfo::RemoteDrive:
{
labelValue = ("Remote Drive");
break;
}
case QSystemStorageInfo::CdromDrive:
{
labelValue = ("CD ROM Drive");
break;
}
default:
{
break;
}
}
ui.driveTypeLabel->setText(labelValue);
}
void SystemStorageInfo::resetAllFields()
{
ui.driveComboBox->setCurrentIndex(0);
ui.availabelDiscSpaceLabel->clear();
ui.totalDiscSpaceLabel->clear();
ui.driveTypeLabel->clear();
}
Output
Useful functions
- QStringList logicalDrives ();
- qlonglong availableDiskSpace ( const QString & volumeDrive );
- qlonglong totalDiskSpace ( const QString & volumeDrive );
- QSystemStorageInfo::DriveType typeForDrive ( const QString & driveVolume );
Headers
- #include <qsysteminfo.h>
Classes
- QSystemStorageInfo
- QString
- QStringList
- QButton
- QLabel
- QComboBox
Example Application
- A working example application is available to download from here: QSystemStorageInfo.zip
Related articles
- Getting started with Qt Mobility APIs
- 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 QSystemDisplayInfo - System Information API
- Working with QSystemNetworkInfo - System Information API - Part 1
- Working with QSystemNetworkInfo - System Information API - Part 2




Itapadar - Tried your App with Qt Creator, but showed some link errors
Hi,
I tried your app with Qt Creator, but am seeing some link errors, any idea, if I need to do something extra in Qt Creator to build Qt Mobility apps?
Regards,itapadar 11:12, 12 December 2011 (EET)
Kiran10182 - Use the latest Qt SDK with the latest Qt Mobility API support built in
@Itapadar: First of all thanks for your question. I created this article a year ago and so many things have been changed since then. You should really try the latest Qt SDK (https://www.developer.nokia.com/info/sw.nokia.com/id/da8df288-e615-443d-be5c-00c8a72435f8/Qt_SDK.html). The latest Qt SDK should will have up to date Qt Mobility support and it should work out of the box for you. So please try to use the latest Qt SDK along with this Qt Mobility API reference: http://doc.qt.nokia.com/qtmobility-1.2/index.html
Thanks.kiran10182 11:28, 12 December 2011 (EET)
Hamishwillee - If you retest ...
Please update the ArticleMetaData indicating the latest SDK used and devices tested against!hamishwillee 01:31, 13 December 2011 (EET)