Filepath in IOS
-
I asked already in a [SOLVED] Post:
https://forum.qt.io/topic/57440/solved-how-to-create-folder-for-save-get-data-in-ios-by-using-widget-code/2
Which was obviously not very intelligent. You can answer there or also here. Thx. -
SGaist already answered your question in the previous post
-
I saw it, but it didn't work.
-
Is there any other place in IOS where I can create a file with QFile? A path that every device has, like on android the /sdcard/appname path for example?
-
-
Is there any other place in IOS where I can create a file with QFile? A path that every device has, like on android the /sdcard/appname path for example?
@Marco-Polo On iOS it is intended that you create your output or bundle input files in the Documents folder of your app bundle. To provide platform-independent output, you will need to explicitly check the platform before attempting to create your file. For example, this is something that we use:
QString log_dir = "../output/"; #ifdef Q_OS_IOS log_dir = QStandardPaths::writableLocation( QStandardPaths::DocumentsLocation) + '/'; #endif std::string log_filename(log_dir.toLocal8Bit().data()); log_filename += "TAPDisplay_Log_" + unique_tag + ".txt";
This covers us for Windows/Linux and iOS. You'll probably have similar restrictions on the Android as to where you can write data.
-
Ok, I could solve it on my IPod touch (IOS 6.1.6), everything worked, so I loaded it up on the App Store. On an IPhone (IOS 7) of my colleague it didn't work. I had used another approach => I used the macro Q_INIT_RESOURCE in my main.cpp and the path with QStandardPahts::...
Now I don't know how exactly to use your approach because I tried and it didn't work. -
Ok, I could solve it on my IPod touch (IOS 6.1.6), everything worked, so I loaded it up on the App Store. On an IPhone (IOS 7) of my colleague it didn't work. I had used another approach => I used the macro Q_INIT_RESOURCE in my main.cpp and the path with QStandardPahts::...
Now I don't know how exactly to use your approach because I tried and it didn't work.@Marco-Polo I am not sure what problems you are having. We have built our software for iOS 7 through 9.1 on iPad and iPhone without a problem. It seems if you are having to use Q_INIT_RESOURCE suggests you are trying to do something a bit differently than we are. I don't see how working with a filepath should have a tie-in to the Qt resource system.
The code snippet I posted constructs the proper path and file name to set the path to the Documents folder in the app bundle. Perhaps if you could post a code snippet of what you're trying, I could give you more help
-
Ok my main.cpp looks as follows:
@
#include "dialog.h"
#include <QApplication>int main(int argc, char *argv[])
{
Q_INIT_RESOURCE(data);
QApplication a(argc, argv);Dialog w; w.show(); return a.exec();
}
@
the filepath part:
@
Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{
ui->setupUi(this);
this->showFullScreen();
//file.setFileName(dir.absolutePath()+"Database.txt");
//file.setFileName(QStandardPaths::writableLocation(QStandardPaths::DataLocation)+"Datab.txt");
//file.setFileName("Database.txt");QString log_dir = "../output/"; #ifdef Q_OS_IOS log_dir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation) + '/'; #endif std::string log_filename(log_dir.toLocal8Bit().data()); log_filename += "TAPDisplay_Log_Data.txt"; file.setFileName(log_dir); bild = new QImage(this->width(), this->height(), QImage::Format_RGB32); load();
@
this load() function:
@
void Dialog::load()
{
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
{return;}
QDataStream in(&file);
in.setVersion(QDataStream::Qt_5_4);
in >> map;file.close();
}
@
and the save function is similar.I hope this is useful.
-
Could it also work with QDir::absolutePath, because on android this worked. Maybe I could add something, so it would work.
-
Ok my main.cpp looks as follows:
@
#include "dialog.h"
#include <QApplication>int main(int argc, char *argv[])
{
Q_INIT_RESOURCE(data);
QApplication a(argc, argv);Dialog w; w.show(); return a.exec();
}
@
the filepath part:
@
Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{
ui->setupUi(this);
this->showFullScreen();
//file.setFileName(dir.absolutePath()+"Database.txt");
//file.setFileName(QStandardPaths::writableLocation(QStandardPaths::DataLocation)+"Datab.txt");
//file.setFileName("Database.txt");QString log_dir = "../output/"; #ifdef Q_OS_IOS log_dir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation) + '/'; #endif std::string log_filename(log_dir.toLocal8Bit().data()); log_filename += "TAPDisplay_Log_Data.txt"; file.setFileName(log_dir); bild = new QImage(this->width(), this->height(), QImage::Format_RGB32); load();
@
this load() function:
@
void Dialog::load()
{
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
{return;}
QDataStream in(&file);
in.setVersion(QDataStream::Qt_5_4);
in >> map;file.close();
}
@
and the save function is similar.I hope this is useful.
@Marco-Polo I am sorry for the delay. I did not see that you replied. Please include my name (by hitting reply), so I can get notified of your response.
What I am seeing in your code is that you are calling ::setFileName() with "log_dir".
file.setFileName(log_dir);
This does not contain the actual file name. In the code, I set the log_dir to the path to the writable documents location, then append the actual target filename to the path. That is what should be passed to the QFile. I am not sure how it works on any iOS device as written. Shouldn't it be:
file.setFileName(log_filename);