First of all thanks ChrisW67 for the Quick response

Coming to the Question now i am trying it this way ..

My code is
Connection. h
Qt Code:
  1. #ifndef CONNECTION_H
  2. #define CONNECTION_H
  3.  
  4.  
  5. #include <QMessageBox>
  6. #include <QtSql/QSQLiteDriver>
  7. #include <QtSql/QSqlError>
  8. #include <QtSql/QSqlQuery>
  9. #include <QDebug>
  10.  
  11.  
  12.  
  13.  
  14. static bool createConnection()
  15. {
  16. QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
  17.  
  18. db.setDatabaseName("./RMD0_2.db");
  19.  
  20. db.open();
  21.  
  22. qDebug()<< db <<db.isOpen();
  23.  
  24. if (!db.open()) {
  25. QMessageBox::critical(0, qApp->tr("Cannot open database"),
  26. qApp->tr("Unable to establish a database connection.\n"
  27. "This example needs SQLite support. Please read "
  28. "the Qt SQL driver documentation for information how "
  29. "to build it.\n\n"
  30. "Click Cancel to exit."), QMessageBox::Cancel);
  31. return false;
  32. }
  33.  
  34. return true;
  35.  
  36.  
  37.  
  38. }
  39.  
  40.  
  41. #endif // CONNECTION_H
To copy to clipboard, switch view to plain text mode 

And the main.cpp

Qt Code:
  1. #include <QtGui/QApplication>
  2. #include "mainwindow.h"
  3. #include <connection.h>
  4. #include <QMessageBox>
  5.  
  6. int main(int argc, char *argv[])
  7. {
  8. QApplication a(argc, argv);
  9.  
  10. if (!createConnection()){
  11.  
  12. return 1;
  13. }
  14.  
  15. MainWindow w;
  16. w.show();
  17.  
  18. return a.exec();
  19. }
To copy to clipboard, switch view to plain text mode 


The mainwindow.cpp

Qt Code:
  1. void MainWindow::menuAction()
  2. {
  3.  
  4. QString qexe= "SELECT STAFF_ID FROM EVENT_STAFF WHERE EVENT_STAFF_ID = 2";
  5. q.prepare(qexe);
  6. if(!q.exec())
  7. qDebug()<< q.lastError();
  8. else
  9. mm.show();
  10.  
  11. }
To copy to clipboard, switch view to plain text mode 

my out put is :
QSqlDatabase(driver=""QSQLITE"", database=""./RMD0_2.db"", host="""", port=-1, user="""", open=true) true

and when i click on button menuAction in the mainwindow.cpp
QSqlError(-1, "Unable to fetch row", "No query")

what can be the problem.?