I am facing problem in openning sqlite database from Qt using QSqlDatabase. The db file and relevant tables are already created.
Single row is also inserted.

What can be the issue ? Tried configuring Qt Source with option "-qt-sql-sqlite" as given in help but no luck

Output after running application is:


Error!!!....openning db

LastError= ""
Rows affected = 0


Sample Code:

Qt Code:
  1. #include <QCoreApplication>
  2. #include <QtSql>
  3. #include <QDebug>
  4.  
  5. int main(int argc, char *argv[])
  6. {
  7. QCoreApplication app(argc, argv);
  8. QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
  9. db.setDatabaseName("/home/data/db/sample.db");
  10.  
  11. if(!db.open())
  12. {
  13. qDebug() << "Database successfully opened...!!! go ahead !!!" << endl;
  14. }
  15. else
  16. {
  17. qDebug() << "Error!!!....openning db" << endl;
  18. qDebug() << "LastError= " << db.lastError().databaseText();
  19. }
  20.  
  21. QSqlQuery query;
  22. query.prepare("SELECT * FROM USER_INFO");
  23. query.exec();
  24.  
  25. qDebug() << "Rows affected = " << query.numRowsAffected() << endl;
  26.  
  27. db.close();
  28. app.exec();
  29. }
To copy to clipboard, switch view to plain text mode 

Project Pro file:

Qt Code:
  1. #-------------------------------------------------
  2. #
  3. # Project created by QtCreator 2012-10-14T19:20:29
  4. #
  5. #-------------------------------------------------
  6.  
  7. QT += core
  8.  
  9. QT -= gui
  10. QT += sql
  11.  
  12. TARGET = DBTest
  13. CONFIG += console
  14. CONFIG -= app_bundle
  15.  
  16. TEMPLATE = app
  17.  
  18. SOURCES += main.cpp
  19.  
  20. unix:!macx:!symbian: LIBS += -L$$PWD/../../../../opt/QtSDK/QtCreator/lib/qtcreator/plugins/sqldrivers/ -lqsqlite
  21.  
  22. INCLUDEPATH += $$PWD/../../../../opt/QtSDK/Desktop/Qt/4.8.1/gcc/include/Qt
  23. DEPENDPATH += $$PWD/../../../../opt/QtSDK/Desktop/Qt/4.8.1/gcc/include/Qt
To copy to clipboard, switch view to plain text mode