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. Filepath in IOS
Forum Update on Monday, May 27th 2025

Filepath in IOS

Scheduled Pinned Locked Moved Solved Mobile and Embedded
11 Posts 4 Posters 2.9k 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.
  • M Offline
    M Offline
    Marco Polo
    wrote on 26 Jan 2016, 20:29 last edited by
    #1

    I asked already in a [SOLVED] Post:
    https://forum.qt.io/topic/57440/solved-how-to-create-folder-for-save-get-data-in-ios-by-using-widget-code/2
    Which was obviously not very intelligent. You can answer there or also here. Thx.

    1 Reply Last reply
    0
    • J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 27 Jan 2016, 05:58 last edited by
      #2

      SGaist already answered your question in the previous post

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

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Marco Polo
        wrote on 27 Jan 2016, 10:21 last edited by
        #3

        I saw it, but it didn't work.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          Marco Polo
          wrote on 27 Jan 2016, 16:16 last edited by
          #4

          Is there any other place in IOS where I can create a file with QFile? A path that every device has, like on android the /sdcard/appname path for example?

          D 1 Reply Last reply 28 Jan 2016, 20:37
          0
          • K Offline
            K Offline
            kolegs
            wrote on 28 Jan 2016, 09:39 last edited by
            #5

            check this out http://forum.qt.io/topic/45601/solved-ios-8beta-qt-5-3-1-problem-with-writing-data-to-file/2

            1 Reply Last reply
            0
            • M Marco Polo
              27 Jan 2016, 16:16

              Is there any other place in IOS where I can create a file with QFile? A path that every device has, like on android the /sdcard/appname path for example?

              D Offline
              D Offline
              DRoscoe
              wrote on 28 Jan 2016, 20:37 last edited by
              #6

              @Marco-Polo On iOS it is intended that you create your output or bundle input files in the Documents folder of your app bundle. To provide platform-independent output, you will need to explicitly check the platform before attempting to create your file. For example, this is something that we use:

                QString log_dir = "../output/";
              #ifdef Q_OS_IOS
                log_dir = QStandardPaths::writableLocation(
                                                  QStandardPaths::DocumentsLocation) + '/';
              #endif
                std::string log_filename(log_dir.toLocal8Bit().data());
              
                log_filename += "TAPDisplay_Log_" + unique_tag + ".txt";
              

              This covers us for Windows/Linux and iOS. You'll probably have similar restrictions on the Android as to where you can write data.

              1 Reply Last reply
              0
              • M Offline
                M Offline
                Marco Polo
                wrote on 4 Feb 2016, 09:20 last edited by Marco Polo 2 Apr 2016, 09:22
                #7

                Ok, I could solve it on my IPod touch (IOS 6.1.6), everything worked, so I loaded it up on the App Store. On an IPhone (IOS 7) of my colleague it didn't work. I had used another approach => I used the macro Q_INIT_RESOURCE in my main.cpp and the path with QStandardPahts::...
                Now I don't know how exactly to use your approach because I tried and it didn't work.

                D 1 Reply Last reply 4 Feb 2016, 14:34
                0
                • M Marco Polo
                  4 Feb 2016, 09:20

                  Ok, I could solve it on my IPod touch (IOS 6.1.6), everything worked, so I loaded it up on the App Store. On an IPhone (IOS 7) of my colleague it didn't work. I had used another approach => I used the macro Q_INIT_RESOURCE in my main.cpp and the path with QStandardPahts::...
                  Now I don't know how exactly to use your approach because I tried and it didn't work.

                  D Offline
                  D Offline
                  DRoscoe
                  wrote on 4 Feb 2016, 14:34 last edited by
                  #8

                  @Marco-Polo I am not sure what problems you are having. We have built our software for iOS 7 through 9.1 on iPad and iPhone without a problem. It seems if you are having to use Q_INIT_RESOURCE suggests you are trying to do something a bit differently than we are. I don't see how working with a filepath should have a tie-in to the Qt resource system.

                  The code snippet I posted constructs the proper path and file name to set the path to the Documents folder in the app bundle. Perhaps if you could post a code snippet of what you're trying, I could give you more help

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    Marco Polo
                    wrote on 5 Feb 2016, 08:41 last edited by Marco Polo 2 May 2016, 08:42
                    #9

                    Ok my main.cpp looks as follows:
                    @
                    #include "dialog.h"
                    #include <QApplication>

                    int main(int argc, char *argv[])
                    {
                    Q_INIT_RESOURCE(data);
                    QApplication a(argc, argv);

                    Dialog w;
                    w.show();
                    
                    return a.exec();
                    

                    }
                    @
                    the filepath part:
                    @
                    Dialog::Dialog(QWidget *parent) :
                    QDialog(parent),
                    ui(new Ui::Dialog)
                    {
                    ui->setupUi(this);
                    this->showFullScreen();
                    //file.setFileName(dir.absolutePath()+"Database.txt");
                    //file.setFileName(QStandardPaths::writableLocation(QStandardPaths::DataLocation)+"Datab.txt");
                    //file.setFileName("Database.txt");

                    QString log_dir = "../output/";
                    #ifdef Q_OS_IOS
                      log_dir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation) + '/';
                    #endif
                      std::string log_filename(log_dir.toLocal8Bit().data());
                    
                      log_filename += "TAPDisplay_Log_Data.txt";
                    
                      file.setFileName(log_dir);
                    
                    bild = new QImage(this->width(), this->height(), QImage::Format_RGB32);
                    
                    load();
                    

                    @
                    this load() function:
                    @
                    void Dialog::load()
                    {
                    if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
                    {return;}
                    QDataStream in(&file);
                    in.setVersion(QDataStream::Qt_5_4);
                    in >> map;file.close();
                    }
                    @
                    and the save function is similar.

                    I hope this is useful.

                    D 1 Reply Last reply 16 Feb 2016, 19:41
                    0
                    • M Offline
                      M Offline
                      Marco Polo
                      wrote on 6 Feb 2016, 16:47 last edited by
                      #10

                      Could it also work with QDir::absolutePath, because on android this worked. Maybe I could add something, so it would work.

                      1 Reply Last reply
                      0
                      • M Marco Polo
                        5 Feb 2016, 08:41

                        Ok my main.cpp looks as follows:
                        @
                        #include "dialog.h"
                        #include <QApplication>

                        int main(int argc, char *argv[])
                        {
                        Q_INIT_RESOURCE(data);
                        QApplication a(argc, argv);

                        Dialog w;
                        w.show();
                        
                        return a.exec();
                        

                        }
                        @
                        the filepath part:
                        @
                        Dialog::Dialog(QWidget *parent) :
                        QDialog(parent),
                        ui(new Ui::Dialog)
                        {
                        ui->setupUi(this);
                        this->showFullScreen();
                        //file.setFileName(dir.absolutePath()+"Database.txt");
                        //file.setFileName(QStandardPaths::writableLocation(QStandardPaths::DataLocation)+"Datab.txt");
                        //file.setFileName("Database.txt");

                        QString log_dir = "../output/";
                        #ifdef Q_OS_IOS
                          log_dir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation) + '/';
                        #endif
                          std::string log_filename(log_dir.toLocal8Bit().data());
                        
                          log_filename += "TAPDisplay_Log_Data.txt";
                        
                          file.setFileName(log_dir);
                        
                        bild = new QImage(this->width(), this->height(), QImage::Format_RGB32);
                        
                        load();
                        

                        @
                        this load() function:
                        @
                        void Dialog::load()
                        {
                        if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
                        {return;}
                        QDataStream in(&file);
                        in.setVersion(QDataStream::Qt_5_4);
                        in >> map;file.close();
                        }
                        @
                        and the save function is similar.

                        I hope this is useful.

                        D Offline
                        D Offline
                        DRoscoe
                        wrote on 16 Feb 2016, 19:41 last edited by
                        #11

                        @Marco-Polo I am sorry for the delay. I did not see that you replied. Please include my name (by hitting reply), so I can get notified of your response.

                        What I am seeing in your code is that you are calling ::setFileName() with "log_dir".

                        file.setFileName(log_dir);
                        

                        This does not contain the actual file name. In the code, I set the log_dir to the path to the writable documents location, then append the actual target filename to the path. That is what should be passed to the QFile. I am not sure how it works on any iOS device as written. Shouldn't it be:

                        file.setFileName(log_filename);
                        
                        1 Reply Last reply
                        0

                        • Login

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