Hi all,

I am experiencing trouble executing a sqlite SELECT query using the Qt library(4.5.0). Finally i broke it down to this small example app, which fails after executing the SELECT query without reporting an error, but query.isValid() returns false. Initializing the database and inserting values is fine and the sqlite command line utility is able to show the created entries, only Qt fails.

Qt Code:
  1. #include <QtGui/QApplication>
  2. #include <QMessageBox>
  3. #include <QSqlDatabase>
  4. #include <QSqlQuery>
  5. #include <QSqlError>
  6.  
  7.  
  8. int main(int argc, char *argv[])
  9. {
  10. QApplication a(argc, argv);
  11. QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
  12. db.setDatabaseName("test.db");
  13. db.open();
  14. QSqlQuery query = db.exec("CREATE TABLE vars "
  15. "(id integer primary key,"
  16. "name VARCHAR( 250 ),"
  17. "value VARCHAR( 250 ))");
  18. QSqlError err = db.lastError();
  19. if(!err.text().size() > 1)
  20. QMessageBox::information(0,"Error creating Database",err.text());
  21.  
  22. query = db.exec("INSERT INTO `vars` ( `name` , `value` ) VALUES ( 'testvar', 'testval');");
  23. err = db.lastError();
  24. if(!err.text().size() > 1)
  25. QMessageBox::information(0,"Error inserting to Database",err.text());
  26.  
  27. query = db.exec("SELECT * from vars;");
  28. err = db.lastError();
  29. if(!err.text().size() > 1)
  30. QMessageBox::information(0,"Error inserting to Database",err.text());
  31. if(!query.isValid()) {
  32. QMessageBox::information(0,"SELECT query not valid!",err.text());
  33. }
  34. if(!query.size()>0)
  35. QMessageBox::information(0,"SELECT result","At least one result read!");
  36. else
  37. QMessageBox::information(0,"SELECT failed","Select failed!");
  38.  
  39. return a.exec();
  40. }
To copy to clipboard, switch view to plain text mode 

Can someone tell my what I am missing?

Thanks,
garfield85