Frage

I have an app that handles multiple databases which the users edits and i would also like it to open them from a specified path (like i get the path using QFileDialog).

Also I saw that it saves the databases files where the executable file is but is there a way i can make it to save them in another place?

War es hilfreich?

Lösung

If you are working with sqlite, then you just need to pass to db.setDatabaseName(file_name) (where db is the connection) the path to the file, that you can select with QFileDialog.

If you are working with other database, then you probably just connect to a database server.

Andere Tipps

First of all which database are you working with; MySQL, SQLite. In case you are working with SQLite this is really easy. You specify a filename when you add the database. So for example:

//get the database file with QFileDialog
QString fileName = QFileDialog::getOpenFileName(this,
 tr("Open Database"), "/home/yourhome", tr("SQLite Database Files (*.sqlite)"));

//add the new database
QSqlDatabase db = QSqlDatabase::addDatabase("SQLITE");
db.setHostName("localhost");
db.setDatabaseName(fileName);
//now your database will be stored in fileName
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top