Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Call for Presentations - Qt World Summit

    Solved Filepath in IOS

    Mobile and Embedded
    4
    11
    2349
    Loading More Posts
    • 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
      Marco Polo last edited by

      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 Reply Quote 0
      • jsulm
        jsulm Lifetime Qt Champion last edited by

        SGaist already answered your question in the previous post

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

        1 Reply Last reply Reply Quote 0
        • M
          Marco Polo last edited by

          I saw it, but it didn't work.

          1 Reply Last reply Reply Quote 0
          • M
            Marco Polo last edited by

            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 Reply Quote 0
            • K
              kolegs last edited by

              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 Reply Quote 0
              • D
                DRoscoe @Marco Polo last edited by

                @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 Reply Quote 0
                • M
                  Marco Polo last edited by Marco Polo

                  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 Reply Quote 0
                  • D
                    DRoscoe @Marco Polo last edited by

                    @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 Reply Quote 0
                    • M
                      Marco Polo last edited by Marco Polo

                      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 Reply Quote 0
                      • M
                        Marco Polo last edited by

                        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 Reply Quote 0
                        • D
                          DRoscoe @Marco Polo last edited by

                          @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 Reply Quote 0
                          • First post
                            Last post