SQLite (Drill Down example)
-
Aloá,
i have started off with Databases by consulting the DrillDown example
and there is something in the connectoin.h and view.cpp I haven´t understood.https://doc.qt.io/qt-6/qtsql-drilldown-example.html
-> code
https://code.qt.io/cgit/qt/qtbase.git/tree/examples/sql/drilldown?h=6.6
-> connection.h with creation and connection of database
https://code.qt.io/cgit/qt/qtbase.git/tree/examples/sql/connection.h?h=6.6In the connection.h file - the database is opened "db.open()"
and when "query.exec("...."); is executed, Query "magically" know "how to write to the database".
Intuitivly I´d have expected, that on creation of 'query' the instance would need something like a socket, a stream or any reference to the opened db.
What is the principle, I´m missing? I guess it also has to do with the fact, that createConnection() is static?I´m wondering the same for in the view.cpp file in the constructor, where the QSqlRelationalTableModel-instance gets created.
itemTable = new QSqlRelationalTableModel(this);
-
@Flaming-Moe When you construct a QSqlQuery without any arguments, or with only a query string, then the database argument defaults to an invalid QSqlDatabase object. In this circumstance the query object will be associated with the default database, i.e. the QSqlDatabase object returned by QSqlDatabase::database().