If you opens db connection in 1.cpp file in 2.cpp file You use it like this :
Qt Code:
  1. QSqlDatabase customer = QSqlDatabase::database();
  2. QSqlQuery qry1;
  3. qr1.prepare(...);
  4. ...
  5. customer.close();
To copy to clipboard, switch view to plain text mode 
Reading the documentation does not hurt. From QSqlDatabase::QSqlDatabase doc : Creates an empty, invalid QSqlDatabase object. Use addDatabase(), removeDatabase(), and database() to get valid QSqlDatabase objects.