[SOLVED][iOS 8beta][Qt 5.3.1]Problem with writing data to file
-
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?
-
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.
-
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.
-
Don't assume things like that e.g. Apple modified several "little" things in 10.9 that gave quiet some headaches to some users.
-
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!