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][iOS 8beta][Qt 5.3.1]Problem with writing data to file

[SOLVED][iOS 8beta][Qt 5.3.1]Problem with writing data to file

Scheduled Pinned Locked Moved Mobile and Embedded
9 Posts 5 Posters 4.4k 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
    kolegs
    wrote on last edited by
    #1

    Hi,

    I got a problem with writing data to file on iOS 8 beta.
    The problem is I cannot see ../Documents folder and cannot create it.

    I tried the code that works very well on iOS 7 but it doesnt work:
    @ QString fileName = "../Documents/abc.txt";
    QFile tf(fileName);
    tf.open(QIODevice::ReadWrite);
    tf.write("TEST");
    tf.close();
    if(QFile::exists(fileName))
    qDebug()<<"abc.txt exists";
    else
    qDebug()<<"abc.txt doesnt exists";@

    Any ideas?

    1 Reply Last reply
    0
    • K Offline
      K Offline
      kolegs
      wrote on last edited by
      #2

      I solved it by looking into some examples.

      There is working code:
      @QString path = QStandardPaths::standardLocations(QStandardPaths::DataLocation).value(0);
      QDir dir(path);
      if (!dir.exists())
      dir.mkpath(path);
      if (!path.isEmpty() && !path.endsWith("/"))
      path += "/";

      qDebug()<<path+"abc.txt";
      QFile tf(path+"abc.txt");
      tf.open(QIODevice::ReadWrite);
      tf.write("TEST");
      tf.close();
      if(QFile::exists(fileName))
          qDebug()<<"abc.txt exists";
      else
          qDebug()<<"abc.txt doesnt exists";
      

      @

      I dont know why, but the paths were wrong.

      1 Reply Last reply
      1
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        Mobile OSes don't behave like desktop OSes. You generally only have access to certain specific folders from your application. You also can't assume that the working directory will be where you application is stored.

        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
        • K Offline
          K Offline
          kolegs
          wrote on last edited by
          #4

          Yeah, but it worked on ios 7 and earlier version, so I assumed that it will also work on ios 8.

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Don't assume things like that e.g. Apple modified several "little" things in 10.9 that gave quiet some headaches to some users.

            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
            • Q Offline
              Q Offline
              qt_erik
              wrote on last edited by
              #6

              Nice work, kolegs!
              Works like a charm on both major mobile OS's.

              1 Reply Last reply
              0
              • Q Offline
                Q Offline
                qt_erik
                wrote on last edited by
                #7

                Nice work, kolegs!
                Works like a charm on both major mobile OS's.

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  m_andrej
                  wrote on last edited by
                  #8

                  Thanks for your snippet, kolegs.
                  It's interesting that in iOS Simulator I can write to current execution directory, but in iOS device I can't. But your snippet works.

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    MLGDN
                    wrote on last edited by
                    #9

                    I am confused by using this way. one time it work well in iOS Simulator and on my moblie, but not effective on another moblie。 Recently it work well on my moblie and another moblie, but a strange phenomenon in iOS Simulator, when Qt run the application it work ok, then I click the application in ios Simulator, it falied to read files.

                    if follow http://doc.qt.io/qt-5/platform-notes-ios.html, use codes like this ios {
                    myXml.files = $$PWD/bin/xx.xml
                    myXml.path = $$PWD/bin
                    QMAKE_BUNDLE_DATA += DEPLOYMENT myXml
                    }

                    how to invoke the local files? use QApplication::applicationDirPath() + ”myXml“ or ”xx.xml“? I have not success!

                    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