title: QSqlDatabase Connecting to Multiple Databases
body: <p>I am having issues attempting to connect to two different databases in one Qt Application. I have my information database that stores all the information collected by the application and the new Log database which allows me to track all the changes that occur to the Application, button presses, screen loads etc, for easy debugging after its release. Separately, the databases work perfectly, but when I try to use both of them, only one will work. I read that this could be because I wasn't naming the connections and obviously only the most recently connected database could use the default connection. However when I give the databases names they wont work at all, isOpen() will return true on both, but as soon as they attempt to execute a query I get the errors</p>
  
  <pre><code>"QSqlQuery::prepare: database not open"
  
  "QSqlError(-1, "Driver not loaded", "Driver not loaded")"
  </code></pre>
  
  <p>My two database declarations are:</p>
  
  <pre><code>database_location = filepath.append("/logger.sqlite");
  logDB = QSqlDatabase::addDatabase("QSQLITE", "LoggerDatabaseConnection");
  logDB.setHostName("localhost");
  logDB.setDatabaseName(database_location);
  </code></pre>
  
  <p>for the Logger Database connection and :</p>
  
  <pre><code>database_location = filepath.append("/db.sqlite");
  db = QSqlDatabase::addDatabase("QSQLITE",  "NormalDB");
  db.setHostName("localhost");
  db.setDatabaseName(database_location);
  </code></pre>
  
  <p>Also when I am running the first query on the databases to see if their tables exist I am using</p>
  
  <pre><code>QSqlQuery query("LoggerDatabaseConnection");
  </code></pre>
  
  <p>and likewise for the normal database, but I am still getting connection issues even after declaring the database connection to run the query on.</p>
  
  <p>The database used for the application is declared as a static QSqlDatabase in a namespace to create a global effect, so everyone can access it, that was a previous programmer, and I created the Log database as Singleton with a private database connection. Like I said both versions of the code work separately but when they are together they are fighting each other. I know there is a huge debate over the proper design of Singleton vs Dependecy Injection, but again the code works separately so I am happy with how it is designed for now. If there is any missing information or if you have any ideas, please let me know. Thank you.</p>