Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. how to open file ? qt for ios?
QtWS25 Last Chance

how to open file ? qt for ios?

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
5 Posts 3 Posters 124 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kkgg
    wrote on 8 Apr 2025, 09:46 last edited by kkgg 4 Aug 2025, 09:46
    #1

    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();
    }
    
    J 1 Reply Last reply 8 Apr 2025, 10:59
    0
    • K kkgg
      8 Apr 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();
      }
      
      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 8 Apr 2025, 10:59 last edited by jsulm 4 Aug 2025, 10:59
      #2

      @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

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      K 1 Reply Last reply 8 Apr 2025, 11:42
      0
      • J Offline
        J Offline
        J.Hilk
        Moderators
        wrote on 8 Apr 2025, 11:21 last edited by
        #3

        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


        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        1 Reply Last reply
        3
        • J jsulm
          8 Apr 2025, 10:59

          @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

          K Offline
          K Offline
          kkgg
          wrote on 8 Apr 2025, 11:42 last edited by
          #4

          @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.

          J 1 Reply Last reply 8 Apr 2025, 11:45
          0
          • K kkgg
            8 Apr 2025, 11:42

            @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.

            J Offline
            J Offline
            jsulm
            Lifetime Qt Champion
            wrote on 8 Apr 2025, 11:45 last edited by
            #5

            @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.

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0

            5/5

            8 Apr 2025, 11:45

            • Login

            • Login or register to search.
            5 out of 5
            • First post
              5/5
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved