Hi,

This is not so much a cry for help as for an explanation. I have always use my database/query sentences in the following way:
Qt Code:
  1. QString app_path = QApplication::applicationDirPath();
  2. QString dbase_path = app_path + "/base.db";
  3.  
  4. QSqlDatabase base = QSqlDatabase::addDatabase("QSQLITE", "db-ident-name");
  5. base.setDatabaseName(dbase_path);
  6. base.database();
  7. base.open();
  8. if(base.isOpen() != true){
  9. qDebug("DB can not be oppened!");
  10. }
  11. else {
  12. // execute query
  13. QSqlQuery sql_string;
  14. sql_string.prepare("SELECT * FROM table");
  15. sql_string.exec();
  16. while ( sql_string.next() ) {
  17. ...
  18. }
  19. }
  20. base.close();
To copy to clipboard, switch view to plain text mode 
and it has worked. Well most of the times it did, sometimes it gave me some strange errors and behaviour, but I always thought that was because of some bug in the code. But on the current project this did not worked until I read on this forum to connect QSqlQuery with QDatabase:
Qt Code:
  1. QSqlQuery sql_string(base);
To copy to clipboard, switch view to plain text mode 
After doing that everything worked fine. Why is this connection necessary and why did the code in previous example worked? What is the difference in both calls? Is the second one safer, more exact?

Thank you, Luka