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][Qt 5.2]QFile doesnt create new file
Forum Updated to NodeBB v4.3 + New Features

[SOLVED][iOS][Qt 5.2]QFile doesnt create new file

Scheduled Pinned Locked Moved Mobile and Embedded
7 Posts 4 Posters 6.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.
  • K Offline
    K Offline
    kolegs
    wrote on last edited by
    #1

    Hi,

    I got a problem i cannot create new file on iPad. There is the code:
    @QFile tf("abc.txt");
    tf.open(QIODevice::ReadWrite);
    tf.write("TEST");
    tf.close();
    if(QFile::exists("abc.txt"))
    qDebug()<<"abc.txt exists";
    else
    qDebug()<<"abc.txt doesnt exists";@

    I keep getting abc.txt doesnt exists in debug console.
    I have no idea why, the code works on linux, mac and android, so why doesnt it work on iOS.

    Thanks

    EDIT: I forgot to mention I alse get this: "QIODevice::write: device not open"

    I believe application doesnt have permission to write on iPad but what should i do to set it?

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      what does the following return?
      @
      qDebug() << QFile("abc.txt").exists();
      @

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • A Offline
        A Offline
        AlexDenisov
        wrote on last edited by
        #3

        Hi, kolegs.
        It doesn't work due to Apple's sandbox policy.
        You're able to write files only to 'Documents' and 'Caches' directories, but not to application's directory.

        This version works as well:

        @ 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";@

        Here is the link where you can read more about this feature:
        https://developer.apple.com/library/mac/documentation/Security/Conceptual/AppSandboxDesignGuide/AboutAppSandbox/AboutAppSandbox.html

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

          Thanks, that's so obvious but I am new to iOS and Mac.

          1 Reply Last reply
          0
          • E Offline
            E Offline
            eduneb
            wrote on last edited by
            #5

            Hi

            it appears that this no longer works in IOS8,

            it now reports:
            QIODevice::write: device not open
            abc.txt doesnt exists

            Any ideas about where we can open a file now

            thank you

            ed

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

              check this out http://qt-project.org/forums/viewthread/47051/

              1 Reply Last reply
              0
              • E Offline
                E Offline
                eduneb
                wrote on last edited by
                #7

                Thank you
                ed

                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