×
Namespaces

Variants
Actions

Using common desktop services in Qt

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Tested with
Devices(s): Nokia 5800 XpressMusic
Compatibility
Platform(s): S60 3rd Edition, FP1, FP2
S60 5th Edition
Symbian
Article
Keywords: QDesktopServices
Created: tepaa (20 May 2009)
Last edited: hamishwillee (11 Oct 2012)

Contents

Overview

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 installed on your platform.


Preconditions

  • Install latest Qt see Qt SDK

Header

#include <QDesktopServices>
#include <QStringList>
#include <QString>
#include <QList>
#include <QDir>
#include <QFileInfoList>
#include <QFileInfo>
 
QList<QString> pictures;


Source

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.developer.nokia.com/"));


See also


Postconditions

The device's image folder is found and opened in the device's built-in picture gallery.

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