QDjango
|
QDjango relies on the QtSql module for database access, which supports a wide array of database drivers.
The first step is to open the database using QSqlDatabase::addDatabase(), for instance for an in-memory SQLite database:
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE"); db.setDatabaseName(":memory:"); db.open();
You should now tell QDjango to use the database you just opened:
QDjango::setDatabase(db);
Once you have set the database and declared all your models (see Database models), you can ask QDjango to create the database tables for all models:
Conversely, you can ask QDjango to drop the database tables for all models:
Internally, QDjango calls the QDjango::database() method whenever it needs a handle to the database. This method will clone the database connection as needed if it is invoked from a different thread.