HI ,
I am using QT4.4 with visual studio 2005. My problem is that how the query is going to executes on database. I am having two files ,main.cpp and connection.h

In connection.h I created a connection and opened it.

connection.h
Qt Code:
  1. bool creatconnection()
  2. {
  3. QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
  4. db.setHostName("bigblue");
  5. db.setDatabaseName("flightdb");
  6. db.setUserName("acarlson");
  7. db.setPassword("1uTbSbAs");
  8. bool ok = db.open();
  9. QSqlQuery.exec(" create table sample(id Integer , Name varchar) ");
  10. retutn true;
  11. }
To copy to clipboard, switch view to plain text mode 

Now in main.cpp I called this function to open and executed one query
main.cpp
Qt Code:
  1. #include <QtGui>
  2.  
  3. #include "../connection.h"
  4.  
  5. int main(int argc, char *argv[])
  6. {
  7. QApplication app(argc, argv);
  8.  
  9. if (!createConnection())
  10. return 1;
  11.  
  12. QSqlQuery.exec(" select * from sample ");
  13.  
  14. return app.exec();
  15. }
To copy to clipboard, switch view to plain text mode 

Every thing is working fine .My doubt is how the query in main.cpp firing on database which I have created in connection.h with out providing the QSqldatabase object. I read the documentation regrading QTSQL module ,which it provides that it call default database. But Here I am not executing query in connection.h ,I am executing in main.cpp ,here how it is able to fire on a particular database in main.cpp.
So I am very much confused about How it is working . Please help me to come out off this confusion.

Please suggest me to solve this problem

Regards,
Sudheer.