May 2019
Intermediate to advanced
542 pages
13h 37m
English
To use a SQL database with QtSQL, we first have to establish a connection. There are three steps to this:
In MainWindow.__init__(), let's create our database connection:
self.db = qts.QSqlDatabase.addDatabase('QSQLITE')
Rather than directly creating a QSqlDatabase object, we create one by calling the static addDatabase method with the name of the database driver we're going to use. In this case, we're using Qt's SQLite3 driver. Qt 5.12 comes with nine drivers built-in, including ones for MySQL (QMYSQL), PostgreSQL (QPSQL), and ODBC connections (including Microsoft SQL Server) (QODBC). A complete list can be found at https://doc.qt.io/qt-5/qsqldatabase.html#QSqlDatabase-2 ...
Read now
Unlock full access