2

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?

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.