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. [SOLVED] How to create folder for save/get data in iOS by using widget code?
QtWS25 Last Chance

[SOLVED] How to create folder for save/get data in iOS by using widget code?

Scheduled Pinned Locked Moved Mobile and Embedded
iosipadwidgetqt5.4
14 Posts 3 Posters 7.8k 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
    mkdh
    wrote on 4 Aug 2015, 09:23 last edited by mkdh 9 Dec 2015, 01:15
    #1

    Hi,

    I can create folder on macbook pro and my android.
    But I can't create the folder on my iPad.
    I google it.
    I find it is hard to create a folder in the out side of the self-app's folder .
    Hence, I can't create the folder on the root.// It just my guest
    below code is my current code.
    How to fixed it?

        //get available folder
        QDir dir=QDir::rootPath();
        QString myPath=QDir::rootPath()+"sdcard";
    
        QDir* dir1=new QDir(myPath);
        if (!dir1->exists()) {
            dir1->mkpath(".");
        }
        if (dir.cd("sdcard")) {
            myPath=QDir::rootPath()+"sdcard";
            QDir* dir2=new QDir(myPath+"/MyFile");
            if (!dir2->exists()) {
                dir2->mkpath(".");
            }
            myPath+="/MyFile";
            dir.cd(myPath);
        }else{
            dir.cd("/Users/QQQ/Desktop/");
        }
    
    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 4 Aug 2015, 19:52 last edited by
      #2

      Hi,

      You should use QStandardPaths::writableLocation to get a proper path to write to.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Marco Polo
        wrote on 26 Jan 2016, 18:13 last edited by Marco Polo
        #3

        Hi, I tried the same thing (or think it is the same more or less) and tried to use the path QStandardPaths::writableLocation(QStandardPaths::DataLocation)+"filename.txt"). But this does not work.
        On android it was easier by using QDir::absolutePath()+"filename.txt". There has been created automatically such a file with this path, as there was no such one already before (so it worked).
        Is there a way to do it with QDir or something similar? Or what exaxtly would I need if I used QStandardPaths? (because I also tried ...Paths::ApplicationsLocation, ::DocumentsLocation)

        I hope you understand my problem.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 26 Jan 2016, 21:31 last edited by
          #4

          Hi,

          Aren't you missing a separator ? i.e. QStandardPaths::writableLocation(QStandardPaths::DataLocation) + "/filename.txt"

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - 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, 07:14 last edited by Marco Polo
            #5

            I already tried it and tried it now again. Does not work unfortunately.
            The path it gave me (when I used qDebug() << file.fielname) was:
            /var/mobile/Applications/262093E8-F9A7-4624-9559-FB3C6BF393E5/Library/Application Support/filename.txt
            Maybe the problem is that there is a space between Application and Support?

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 27 Jan 2016, 21:47 last edited by
              #6

              No, that should not be a problem. What error do you get from your file ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - 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, 22:10 last edited by Marco Polo
                #7

                Well, the interesting thing is that I get no error, I only see that the data has not been saved after I restarted the app. What path would I use with qrc? Because I also tried it with that => path ":/data/filename.txt", that is the path qt also tells I should take, but this works only if I run it on my mac. Do I have to include something in the .pro file?

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 27 Jan 2016, 22:19 last edited by
                  #8

                  Just to be sure I understand you correctly, do you want to read a file from qrc and store it on the device ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - 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, 22:30 last edited by Marco Polo
                    #9

                    yes, but I also like the other version if the data can be saved (sorry my english migth be unclear sometimes, I'm from switzerland)

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on 27 Jan 2016, 22:34 last edited by
                      #10

                      No no, your english is not that bad, it was just to confirm I understood you correctly.

                      Since it's on iOS you may have to use the Q_INIT_RESOURCE macro to make your resources accessible.

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0
                      • M Offline
                        M Offline
                        Marco Polo
                        wrote on 28 Jan 2016, 05:49 last edited by Marco Polo
                        #11

                        Ok, I see it should work with that, but what line exactly do I have to add in main.cpp when I have Resources=>data.qrc=>/=>Database.txt or the "normal" path :/Database.txt? Because I tried many lines again and don't know where the error is.

                        1 Reply Last reply
                        0
                        • S Offline
                          S Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on 28 Jan 2016, 08:26 last edited by
                          #12

                          IIRC:

                          Q_INIT_RESOURCE(data);
                          

                          And then you can use the path like normal.

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                          1 Reply Last reply
                          0
                          • M Offline
                            M Offline
                            Marco Polo
                            wrote on 28 Jan 2016, 08:58 last edited by Marco Polo
                            #13

                            I don't know why, but it works now, I inserted the line in the main.cpp, but used the QStandardPaths::... Thank you very much!

                            1 Reply Last reply
                            0
                            • S Offline
                              S Offline
                              SGaist
                              Lifetime Qt Champion
                              wrote on 28 Jan 2016, 09:56 last edited by
                              #14

                              qrc is a read-only system by design. Otherwise it would mean that you can rewrite your executable in place.

                              You're welcome !

                              By the way, no need to modify the title to mark the thread as solved, the "Topic Tool" button is there for that :)

                              Interested in AI ? www.idiap.ch
                              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                              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