Do SQL connections remain available system-wide from any class after they are opened?
-
After opening an Sqlite database, I am wondering why it is possible to run queries in other functions that do not specifically refer to the database you opened. How is it that a query just works? What if you had multiple databases open, how do queries know where to connect to?
-
Hi,
The QSqlQuery uses the default database connection by default. If you want to act on another connection, you have the give it as parameter when creating the query.
-
If you don't give it a name, it replaces the current default
-
I use the setDatabaseName function, which seems to be what is necessary to create an actual file by the name passed to this function, but it must also become the default connection even if I use this function, since other functions are querying correctly without being passed any connection information. Does this sound right?
-
To create the file yes, but it has nothing to do with the connection handling. The default connection was replaced when you called QSqlDatabase::addDatabase("QSQLITE");