I found a solution but I do not understand why it is working.
First I create a static member function in mainWindow:

Qt Code:
  1. bool mainWindow::createConnStatic()
  2. {
  3. QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
  4.  
  5. }
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
Qt Code:
  1. QSqlDatabase db = QSqlDatabase::database();
  2. 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.