I have been trying to SELECT records from a mysql database. The QMYSQL driver works fine for INSERT, CREATE TABLE and other query statements except SELECT statements. Anytime I run my code, I get an error which says:

QMYSQL3: Unable to fetch data

Another confusing thing this is that I have three database drivers:
QMYSQL3, QMYSQL and QSQLITE.
When I use QMYSQL in my code, the application runs with QMYSQL3. Could this be the source of my problems?

Here's mycode:

Qt Code:
  1. db = QSqlDatabase::addDatabase("QMYSQL");
  2. db.setHostName("dbhost");
  3. db.setDatabaseName("dbname");
  4. db.setUserName("dbuser");
  5. db.setPassword("dbpasswd");
  6. db.setPort(3306);
  7. if (db.open()){
  8. cerr<<"Connected!";
  9. QSqlQuery query;
  10. query.exec("SELECT now()");
  11. while (query.next()){
  12. cerr<<"-- "<<qPrintable(query.value(0).toString());
  13. }
  14. cerr<<"\nExec: "<< query.executedQuery().toStdString();
  15. QSqlError err = query.lastError();
  16. qDebug()<<"\nError: "<< query.lastError().text();
  17. }
  18. else
  19. {
  20. cerr<<"\n\nNot Connected!";
  21. }
To copy to clipboard, switch view to plain text mode 

What am I doing wrong?

I am using the 2009.04 version of QT4 and mysql 5.0.45