Hello,

I was trying to build a simple connection to my database that i created recently. But it seems my code doesn't work or sth else wrong. Actually I want to show the values from database file.

Here's the code :


Qt Code:
  1. #include <QtCore/QCoreApplication>
  2. #include <QtSql>
  3. #include <QtDebug>
  4. #include <iostream>
  5. using namespace std;
  6.  
  7. int main(int argc, char *argv[])
  8. {
  9. QCoreApplication a(argc, argv);
  10.  
  11.  
  12.  
  13. QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
  14.  
  15. db.setConnectOptions();
  16.  
  17. db.setDatabaseName("deneme");
  18. db.setHostName("localhost");
  19. db.setUserName("root");
  20. db.setPassword("2245009");
  21.  
  22.  
  23. if(db.open())
  24. {
  25. cout<<"opened"<<endl;
  26.  
  27. QSqlQuery qry;
  28. if(qry.exec("SELECT *FROM `tablo` 1"))
  29.  
  30. {
  31. while(qry.next())
  32. {
  33. //qDebug() << qry.value(1).toString();
  34. qDebug() << qry.value(1);
  35. }
  36. }
  37. else
  38. {
  39. qDebug() << "error = " << db.lastError().text();
  40. }
  41. cout<<"closing"<<endl;
  42. db.close();
  43.  
  44. }
  45. else
  46. {
  47. qDebug() << "error = " << db.lastError();
  48. }
  49.  
  50. return a.exec();
  51. }
To copy to clipboard, switch view to plain text mode 



The output is like that :

Starting /home/onur/dbapp-build-desktop/dbapp...
opened
closing
error = " "
It shows an empty error. I didn't understand anything because of being a newbie. Any advices?

Thanks in Advance!