title: Connect to SQLite database using qt
body: <p>I am having trouble connecting to my sqlite database using my qt application.
  I have a helper class DBManager that is supposed to have functions to open and close the database, as I would like to reuse the code in multiple places.
  Here is the dbmanager.cpp</p>
  
  <pre><code>DBManager::DBManager()
  {
  
  }
  void DBManager::connOpen()
  {
  
      path = QCoreApplication::applicationDirPath() + "/GameSuitedb.db";
      mydb=QSqlDatabase::addDatabase("QSQLITE");
      mydb.setDatabaseName(path);
  
  void DBManager::connClose() /*Closes connection and commits changes to database*/
  {
      mydb.close();
      mydb.removeDatabase(QSqlDatabase::defaultConnection);
  }
  </code></pre>
  
  <p>Note my database is named GameSuitedb and is located next to the executable
  And here is where I am trying to access my database:</p>
  
  <pre><code>void CreateUser::on_pushButton_submit_clicked()
  {
      dbmanager.connOpen();
      QString username = ui-&gt;lineEdit_username-&gt;text();
      QString password = ui-&gt;lineEdit_password-&gt;text(); //Gets password text
      QSqlQuery qry(dbmanager.mydb);
      qry.prepare("INSERT INTO users (username,password) VALUES ('"+username+"', '"+password+"')");
  
      if(qry.exec()){
      }
      else{
          ui-&gt;statusbar-&gt;showMessage(qry.lastError().text());
      }
          dbmanager.connClose();
  }
  </code></pre>
  
  <p>The error the above code gives me when launched is QSqlQuery::prepare: database not open.</p>