Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Qt中访问公共的桌面服务

From Wiki
Jump to: navigation, search
Article Metadata

测试基于
SDK: Qt for S60 "Garden" technology preview
设备:: Nokia 5800 XpressMusic

兼容于
平台:
Symbian

文章
关键词: QDesktopServices
dougcn 在 22 May 2009 创建
最后由 hamishwillee 在 11 Oct 2012 编辑

Needs-update.png本文需要更新: 如果您发现这篇文章有用,请修复下面的问题,然后从文章中删除 {{ArticleNeedsUpdate}} 模板,以消除此警告。

原因: hamishwillee (21 Oct 2011)
This was written when Qt was in pre-release (garden). It needs to be verified against current releases and the links (now broken) need to be updated to the right place.

Contents

概述

此代码片段演示如何使用QDesktopServices。

QDesktopServices给应用程序提供了执行公共任务的API接口,诸如打开网页、打开图片库、或者从设备中查找电影文件等。

注意: 要使用这段代码,在你的平台上需要装有Qt fro S60。


前提条件

头文件

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


源代码

搜索设备图片文件夹

// Search device picture location directory
QDir picturesDir;
picturesDir.setPath(QDesktopServices::storageLocation
(QDesktopServices::PicturesLocation));

从设备图片文件夹搜索图片

// 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
}
}

打开图片,将进入系统内建的图片库应用程序

QDesktopServices::openUrl(QUrl("file:///" + pictures[0]));

打开网页,将进入系统内建的浏览器应用程序

QDesktopServices::openUrl(QUrl("http://www.developer.nokia.com/"));


参看


后置条件

设备图形文件夹找到了,并打开进入了设备内建的图片库。

This page was last modified on 11 October 2012, at 01:15.
205 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×