how to open file ? qt for ios?
-
wrote 25 days ago last edited by kkgg 4 Aug 2025, 09:46
I am using qt 6.7 to develop iOS. I need to use filedoilg in qml to select the image path, and finally it shows an error: Unable to open file
System error code: 5
Detailed reason: "Operation not permitted"void loadImage(const QString &filePath) { // 检查文件是否存在 // if (!QFileInfo::exists(filePath)) { // qDebug() << "错误:文件不存在"; // return; // } // 检查文件是否可读 QFile file(filePath); if (!file.open(QIODevice::ReadOnly)) { qDebug() << "错误:无法打开文件"; qDebug() << "系统错误码:" << file.error(); qDebug() << "详细原因:" << file.errorString(); return; } file.close(); // 检查格式支持 QImageReader reader(filePath); if (!reader.canRead()) { qDebug() << "错误:不支持此格式或文件损坏"; qDebug() << "错误详情:" << reader.errorString(); return; } // 尝试加载 QImage image; if (!image.load(filePath)) { qDebug() << "错误:加载失败"; return; } qDebug() << "图像加载成功,尺寸:" << image.size(); }
-
I am using qt 6.7 to develop iOS. I need to use filedoilg in qml to select the image path, and finally it shows an error: Unable to open file
System error code: 5
Detailed reason: "Operation not permitted"void loadImage(const QString &filePath) { // 检查文件是否存在 // if (!QFileInfo::exists(filePath)) { // qDebug() << "错误:文件不存在"; // return; // } // 检查文件是否可读 QFile file(filePath); if (!file.open(QIODevice::ReadOnly)) { qDebug() << "错误:无法打开文件"; qDebug() << "系统错误码:" << file.error(); qDebug() << "详细原因:" << file.errorString(); return; } file.close(); // 检查格式支持 QImageReader reader(filePath); if (!reader.canRead()) { qDebug() << "错误:不支持此格式或文件损坏"; qDebug() << "错误详情:" << reader.errorString(); return; } // 尝试加载 QImage image; if (!image.load(filePath)) { qDebug() << "错误:加载失败"; return; } qDebug() << "图像加载成功,尺寸:" << image.size(); }
@kkgg On mobile systems your app has to request permissions for many things, this also includes accessing file. Which permission you need depends where the files you want to access are stored. See https://doc.qt.io/qt-6/permissions.html
-
Unless you're a very special app with very special access and rights granted by either iOS or Android, you won't get access to the fotos folder even with all the permissions of the user.
Nowadays you're supposed to send requests to the OS-Services they than will grant you access to a byte stream of the Foto/File the user granted access to.
I'm unsure if Q6 offers a nice API for this. I used to do it via Objective C & Java calls
-
@kkgg On mobile systems your app has to request permissions for many things, this also includes accessing file. Which permission you need depends where the files you want to access are stored. See https://doc.qt.io/qt-6/permissions.html
wrote 25 days ago last edited by@jsulm said in how to open file ? qt for ios?:
@kkgg On mobile systems your app has to request permissions for many things, this also includes accessing file. Which permission you need depends where the files you want to access are stored. See https://doc.qt.io/qt-6/permissions.html
I didn't find the relevant API. I don't need to access the contents of the album. I just need to access the file system. I opened the file with filedoilg.
-
@jsulm said in how to open file ? qt for ios?:
@kkgg On mobile systems your app has to request permissions for many things, this also includes accessing file. Which permission you need depends where the files you want to access are stored. See https://doc.qt.io/qt-6/permissions.html
I didn't find the relevant API. I don't need to access the contents of the album. I just need to access the file system. I opened the file with filedoilg.
@kkgg said in how to open file ? qt for ios?:
I don't need to access the contents of the album
You're trying to open a file and for this your app needs permissions.
Also consider what @J-Hilk wrote.
1/5