I know that setting the database name for a SQLite database means setting the path to the DB file. I set it like this:
db.setDatabaseName(\"DienstplanerDB.sqlite
a sudo find / -name "DienstplanerDB.sqlite"
spit out that the Database was created within the app package.
If you want to access it, right click on the "YourPorgram.app" and select "Show package content".
The Database could be found at Contents/MacOS/yourDatabase.db
It should be saved in the current directory. To obtain it, use QDir::currentDirectory().
This has nothing to do with sqlite. Or even Qt. Or OS X.
The following project does the same on all platforms.
// main.cpp
#include <fstream>
int main() {
std::ofstream{"DienstplanerDB.sqlite"} << "Ooops" << std::endl;
}
# project.pro (no Qt frameworks are linked to the executable)
CONFIG -= qt
CONFIG += c++11
TARGET = write-bundle-con-32533822
TEMPLATE = app
SOURCES += main.cpp
Now that you found it: you shouldn't have, because it's a wrong question to ask. Wherever it happens to be is out of your control. Why do you expect the initial working directory of your GUI process to be anything in particular? Don't. It's as simple as that. You have no control over it (zip, nada, zero, really). If you wish to locate things relative to the working directory, you must set it first yourself to point somewhere useful. Then there's no question as to where things are. Use QStandardPaths
to get a platform-independent location for your database - AppDataLocation
or AppLocalDataLocation
would be a good choice. Make sure that you set your application name first via QCoreApplication::setApplicationName
.
A properly developed application cannot assume that any initial working directory is writable (or even readable), nor that it has any particular value. Generally, on OS X the app bundle is not writable, just as the install folder isn't on Windows. Just because you can scribble all over it in a developer setting doesn't mean your users can, or that it is a wise thing to do.
Here's what your code just did to your user: They had a system from Yoyodyne, Inc.'s YodelAbteilung Deutschland. It had a DienstplanerDB.sqlite
with €10k worth of data tucked in a safe spot. Did you seriously believe that you're the only person on the planet using sqlite, or dealing with rosters?! Since you write wherever you stand, you just overwrote it. You get sued for damages. Rightly so.
Don't wreck your users' data, please.