Database configuration

Setting the database

The first step is to open the database using QSqlDatabase::addDatabase(), for instance for an in-memory SQLite database:

QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");

You should now tell QDjango to use the database you just opened:

Creating or dropping database tables

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:

Threading support

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.