2

I want to create an app, which has a C++ backend and uses sqlite3. I can connect to an Database in memory using the following code:m_db = QSqlDatabase::addDatabase("QSQLITE"); m_db.setDatabaseName(":memory:"); m_db.open();

But I don't know what path I have to use or whatelse I have to do to create a local database file on my phone. If I run the application on my Computer I can replace ":memory:" by any path I want.

Thanks

1 Answer 1

0

I got the clue from a comment to this question that I can't find anymore.

If you want to write to/read from the filesystem you have to take care of the app confinement of Ubuntu. An normal not OS trusted application can only write to some limited "private" directories and read from some more directories. You can use the QStandardPaths class to find these directories. For example to get the writable data directory I use QStandardPaths::writableLocation(QStandardPaths::DataLocation) and with QStandardPaths::standardLocations(QStandardPaths::DataLocation) you get all readable data directories. It works for me to create my sqlite3 file in the writeable data directory.

By the way: You can get other kinds of directories for your application using QStandardPaths (eg. temp, cache, ...).

The app confinements of Ubuntu are available here.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .