首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在iOS设备Qt创建器C++ QStandardPaths::standardLocations(QStandardPaths::DownloadLo‌​cation);上找不到文件

在iOS设备Qt创建器C++ QStandardPaths::standardLocations(QStandardPaths::DownloadLo‌​cation);上找不到文件
EN

Stack Overflow用户
提问于 2017-10-05 22:29:50
回答 1查看 221关注 0票数 0

我正在使用Qt Creator QStandardPaths::standardLocations(QStandardPaths::DownloadLo‌​cation);C++访问用户的文件,但它没有返回在iOS设备上找到的文件。到目前为止,我的代码如下:

代码语言:javascript
复制
const QStringList
mPathList = QStandardPaths::standardLocations(QStandardPaths::DownloadLo‌​cation);
mPath = QString("%1").arg(mPathList.first());
dirmodel = new QFileSystemModel (this);
dirmodel->setFilter(QDir::AllDirs | QDir::NoDotAndDotDot);
dirmodel->setRootPath(mPath); 
EN

回答 1

Stack Overflow用户

发布于 2017-10-06 18:44:40

在iOS上,所有的应用程序都在自己的沙箱中,你永远无法直接访问应用程序之外的东西/文件。

为此,您需要在运行时从您的应用程序中调用本机iOS应用程序接口。此外,最好不要保存路径以在下次启动应用程序时使用它们,因为iOS会为沙盒中的应用程序生成基于散列的路径,而这些路径可能会在您下次运行应用程序时更改。

下面是如何在Qt中调用本机iOS代码示例。

创建包含以下内容的ios_utils.mm,并将其添加到您工程的源目录中:

代码语言:javascript
复制
#include "ios_utils.h"
#include <QStringList>
#include <UIKit/UIKit.h>
#include <qpa/qplatformnativeinterface.h>


QStringList getiOSHomeFolder()
{
    QStringList retval;

    NSString *item;
    NSArray *contents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:NSHomeDirectory() error:nil];

    for (item in contents)
    {
        retval.append(QString::fromNSString(item));
    }

    return retval;
}

创建ios_utils.h

代码语言:javascript
复制
#ifndef IOSUTILS_H
#define IOSUTILS_H


#ifdef Q_OS_IOS

QStringList getiOSHomeFolder();

#endif // Q_OS_IOS

#endif // IOSUTILS_H

在你的Qt代码中的某处:

代码语言:javascript
复制
#include "ios_utils.h"

qDebug() << getiOSHomeFolder();
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46588201

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档