[SOLVED] How to create folder for save/get data in iOS by using widget code?
-
Hi,
You should use QStandardPaths::writableLocation to get a proper path to write to.
-
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.
-
Hi,
Aren't you missing a separator ? i.e.
QStandardPaths::writableLocation(QStandardPaths::DataLocation) + "/filename.txt"
-
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? -
No, that should not be a problem. What error do you get from your file ?
-
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?
-
Just to be sure I understand you correctly, do you want to read a file from qrc and store it on the device ?
-
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)
-
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.
-
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.
-
IIRC:
Q_INIT_RESOURCE(data);
And then you can use the path like normal.
-
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!
-
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 :)