| ID | CS001426 | Creation date | June 16, 2009 |
| Platform | S60 3rd Edition, FP1, FP2 S60 5th Edition | Tested on devices | Nokia 5800 XpressMusic |
| Category | Qt for Symbian | Subcategory | Base/System |
| Keywords (APIs, classes, methods, functions): QDesktopServices |
This code snippet demonstrates how to use QDesktopServices.
QDesktopServices provides an API for the application to perform common tasks; open a web page, open a picture gallery, or find movie files from the device.
Note: In order to use this code, you need to have Qt for S60 installed on your platform.
#include <QDesktopServices>
#include <QStringList>
#include <QString>
#include <QList>
#include <QDir>
#include <QFileInfoList>
#include <QFileInfo>
QList<QString> pictures;
Search for the device's picture folder:
// Search device picture location directory
QDir picturesDir;
picturesDir.setPath(QDesktopServices::storageLocation
(QDesktopServices::PicturesLocation));
Search for pictures in the device's picture folder:
// Search files from the directory
QFileInfoList fileList = picturesDir.entryInfoList(QStringList(),
QDir::Files | QDir::Dirs, QDir::Time);
for (int i = 0; i < fileList.size(); ++i)
{
QFileInfo fileInfo = fileList.at(i);
if (fileInfo.isHidden())
continue;
#ifndef Q_OS_SYMBIAN
if (fileInfo.filePath().length()>0 &&
fileInfo.filePath().right(1) == ".")
continue;
if (fileInfo.filePath().length()>1 &&
fileInfo.filePath().right(2) == "..")
continue;
#endif
// File found
if (fileInfo.isFile())
{
if (fileInfo.filePath().indexOf(QString(".jpeg")
,0,Qt::CaseInsensitive)>0 ||
fileInfo.filePath().indexOf(QString(".jpg")
,0,Qt::CaseInsensitive)>0)
{
// Store picture path to array
pictures.append(fileInfo.filePath());
}
}
// Direcotry found
else if (fileInfo.isDir())
{
// TODO: we do not handle sub-directoires
}
}
Open the first picture into the device's built-in picture gallery application:
QDesktopServices::openUrl(QUrl("file:///" + pictures[0]));
Open an HTML page into the device's built-in HTML browser application:
QDesktopServices::openUrl(QUrl("http://www.forum.nokia.com"));
The device's image folder is found and opened in the device's built-in picture gallery.
No related wiki articles found