Hey guys,

I'm having this trouble in QT - I was wondering if somebody could explain to me what's going on.

I'm using this code:
Qt Code:
  1. timingDatabase = QSqlDatabase::addDatabase("QSQLITE", "timing");
  2. timingDatabase.setDatabaseName("../config.db");
  3. if (!timingDatabase.open())
  4. {
  5. qDebug() << timingDatabase.lastError();
  6. }
  7.  
  8. if (!timingDatabase.tables().contains("timing"))
  9. ConstructTimeSettingsTable();
To copy to clipboard, switch view to plain text mode 

and also
Qt Code:
  1. void TimingSettings::ConstructTimeSettingsTable()
  2. {
  3. qDebug() << timingDatabase.tables();
  4. QSqlQuery timeQuery;
  5. timeQuery.exec("CREATE TABLE timing ("
  6. "line1 STRING, "
  7. "line2 STRING, "
  8. "line3 STRING"
  9. ");");
  10. qDebug() << timeQuery.lastError();
  11. qDebug() << "Construct function entered.";
  12. }
To copy to clipboard, switch view to plain text mode 


If I am correct - my program should run the Construct...() if the timing table does not exist (i.e. the first time the program is ran).. However, that is not the case - this is the output I am getting from my qDebug everytime I run the program:
Qt Code:
  1. ()
  2. QSqlError(1, "Unable to execute statement", "table timing already exists")
  3. Construct function entered.
To copy to clipboard, switch view to plain text mode 

(1) the first "()" is what timingDatabase.tables() - as in there are no tables in the database, am I right?
(2) if the timingDatabase.tables() is NULL, why is the timingQuery.exec unable to run because the table already exists..?
(3) I've also written debugging code to try to write to and from the database - but the code does not do anything.

If you guys could point me in the right direction of what is wrong with my code, it would be much appreciated.