You Are Here:

Community: Wiki

This page was last modified on 3 September 2009, at 07:39.

CS001426 - Using common desktop services in Qt

From Forum Nokia Wiki


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

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


Preconditions


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


See also


Postconditions

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

Related Wiki Articles

No related wiki articles found

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZidentifierQSxhttpE3aE2fE2fwikiE2eforumE2enokiaE2ecomE2findeE78E2ephpE2fTalkE3aE4cargeE5fscreenE5fsaverX qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqfntypeZWikiContentQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qfnZtypeQUqfntypeZWikiContentQ qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqfntypeZWikiContentQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ