Qt中访问公共的桌面服务
文章信息
测试基于
SDK: Qt for S60 "Garden" technology preview
设备:: Nokia 5800 XpressMusic
文章
关键词: QDesktopServices
由 dougcn
在 22 May 2009 创建
最后由 hamishwillee
在 11 Oct 2012 编辑
本文需要更新: 如果您发现这篇文章有用,请修复下面的问题,然后从文章中删除 {{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.
原因: 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。
前提条件
头文件
源代码
搜索设备图片文件夹
// 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/"));
参看
- 更多信息,请看 QDesktopServices
后置条件
设备图形文件夹找到了,并打开进入了设备内建的图片库。


(no comments yet)