I found a solution but I do not understand why it is working.
First I create a static member function in mainWindow:
bool mainWindow::createConnStatic()
{
}
bool mainWindow::createConnStatic()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
}
To copy to clipboard, switch view to plain text mode
which is declared static in the header file.
Now, at the startup I create a connection by calling this function. db is a member variable.
When I wann change database, I do
db.setDatabaseName(s);
QSqlDatabase db = QSqlDatabase::database();
db.setDatabaseName(s);
To copy to clipboard, switch view to plain text mode
This work pretty well, but is "impossible" to got there by reading the Qt Doc.
Bookmarks