SQL Programming¶
Database integration for Qt applications.
This overview assumes that you have at least a basic knowledge of SQL. You should be able to understand simple
SELECT,INSERT,UPDATE, andDELETEstatements. Although theQSqlTableModelclass provides an interface to database browsing and editing that does not require a knowledge of SQL, a basic understanding of SQL is highly recommended. A standard text covering SQL databases is An Introduction to Database Systems (7th Ed.) by C. J. Date, ISBN 0201385902.
Topics:¶
Database Classes¶
These classes provide access to SQL databases.
qsql.html
The QSql namespace contains miscellaneous identifiers used throughout the Qt SQL module.
PySide2.QtSql.QSqlDriverCreatorBaseThe QSqlDriverCreatorBase class is the base class for SQL driver factories.
QSqlDriverCreatorThe QSqlDriverCreator class is a template class that provides a SQL driver factory for a specific driver type.
PySide2.QtSql.QSqlDatabaseThe QSqlDatabase class handles a connection to a database.
PySide2.QtSql.QSqlDriverThe QSqlDriver class is an abstract base class for accessing specific SQL databases.
PySide2.QtSql.QSqlErrorThe QSqlError class provides SQL database error information.
PySide2.QtSql.QSqlFieldThe QSqlField class manipulates the fields in SQL database tables and views.
PySide2.QtSql.QSqlIndexThe QSqlIndex class provides functions to manipulate and describe database indexes.
PySide2.QtSql.QSqlQueryThe QSqlQuery class provides a means of executing and manipulating SQL statements.
PySide2.QtSql.QSqlRecordThe QSqlRecord class encapsulates a database record.
PySide2.QtSql.QSqlResultThe QSqlResult class provides an abstract interface for accessing data from specific SQL databases.
PySide2.QtSql.QSqlQueryModelThe QSqlQueryModel class provides a read-only data model for SQL result sets.
PySide2.QtSql.QSqlRelationalTableModelThe QSqlRelationalTableModel class provides an editable data model for a single database table, with foreign key support.
PySide2.QtSql.QSqlTableModelThe QSqlTableModel class provides an editable data model for a single database table.
The SQL classes are divided into three layers:
Driver Layer¶
This comprises the classes
QSqlDriver,QSqlDriverCreator,QSqlDriverCreatorBase,QSqlDriverPlugin, andQSqlResult.This layer provides the low-level bridge between the specific databases and the SQL API layer. See SQL Database Drivers for more information.
SQL API Layer¶
These classes provide access to databases. Connections are made using the
QSqlDatabaseclass. Database interaction is achieved by using theQSqlQueryclass. In addition toQSqlDatabaseandQSqlQuery, the SQL API layer is supported byQSqlError,QSqlField,QSqlIndex, andQSqlRecord.
User Interface Layer¶
These classes link the data from a database to data-aware widgets. They include
QSqlQueryModel,QSqlTableModel, andQSqlRelationalTableModel. These classes are designed to work with Qt’s model/view framework .Note that a
QCoreApplicationobject must be instantiated before using any of these classes.
© 2022 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.