我正在使用Qt Creator QStandardPaths::standardLocations(QStandardPaths::DownloadLocation);C++访问用户的文件,但它没有返回在iOS设备上找到的文件。到目前为止,我的代码如下:
const QStringList
mPathList = QStandardPaths::standardLocations(QStandardPaths::DownloadLocation);
mPath = QString("%1").arg(mPathList.first());
dirmodel = new QFileSystemModel (this);
dirmodel->setFilter(QDir::AllDirs | QDir::NoDotAndDotDot);
dirmodel->setRootPath(mPath); 发布于 2017-10-06 18:44:40
在iOS上,所有的应用程序都在自己的沙箱中,你永远无法直接访问应用程序之外的东西/文件。
为此,您需要在运行时从您的应用程序中调用本机iOS应用程序接口。此外,最好不要保存路径以在下次启动应用程序时使用它们,因为iOS会为沙盒中的应用程序生成基于散列的路径,而这些路径可能会在您下次运行应用程序时更改。
下面是如何在Qt中调用本机iOS代码示例。
创建包含以下内容的ios_utils.mm,并将其添加到您工程的源目录中:
#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
#ifndef IOSUTILS_H
#define IOSUTILS_H
#ifdef Q_OS_IOS
QStringList getiOSHomeFolder();
#endif // Q_OS_IOS
#endif // IOSUTILS_H在你的Qt代码中的某处:
#include "ios_utils.h"
qDebug() << getiOSHomeFolder();https://stackoverflow.com/questions/46588201
复制相似问题