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 Updated to NodeBB v4.3 + New Features

Filepath in IOS

Scheduled Pinned Locked Moved Solved Mobile and Embedded
11 Posts 4 Posters 3.0k Views 1 Watching
  • 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.
  • jsulmJ Offline
    jsulmJ Offline
    jsulm
    Lifetime Qt Champion
    wrote on 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 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 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
        0
        • K Offline
          K Offline
          kolegs
          wrote on 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

            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 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 last edited by Marco Polo
              #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
              0
              • M 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 Offline
                D Offline
                DRoscoe
                wrote on 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 last edited by Marco Polo
                  #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
                  0
                  • M Offline
                    M Offline
                    Marco Polo
                    wrote on 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

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