Quote Originally Posted by Lykurg View Post
Declare them always on need in place.
You likely put a wrong database to query.
You are right. I declared it in place where I needed it and gived as an argument my database and it works. Now I'm just curious about something. I've wrote something like this, just to see what will happen (function that should read one thing from database and then close it):

Qt Code:
  1. bool MainWindow::readFromDB()
  2. {
  3. bool ok;
  4. QTextStream out(stdout);
  5.  
  6. QSqlQueryModel queryModel;
  7.  
  8. bdb = QSqlDatabase::addDatabase("QSQLITE","vb");
  9. bdb.setDatabaseName(databaseName);
  10.  
  11. ok = bdb.open();
  12.  
  13. if (ok)
  14. {
  15. queryModel.clear();
  16. queryModel.setQuery("SELECT * FROM table WHERE name='var1'", bdb);
  17.  
  18. rec = queryModel.record(0);
  19. notificationInterval = (rec.value(1).toInt())*1000;
  20.  
  21. rec.clear();
  22. queryModel.clear();
  23. bdb.close();
  24.  
  25. } else {
  26. out << "Nie udalo sie otworzyc bazy!" << endl;
  27. }
  28.  
  29. QSqlDatabase::removeDatabase("vb");
  30.  
  31. return ok;
  32. }
To copy to clipboard, switch view to plain text mode 

And it does what it should but gives in console:

Qt Code:
  1. QSqlDatabasePrivate::removeDatabase: connection 'vb' is still in use, all queries will cease to work.
To copy to clipboard, switch view to plain text mode 

Is is normal behavior?

thanks in advance
best regards
Tomasz