This overview assumes that you have at least a basic knowledge of SQL. You should be able to understand simple
SELECT
,
INSERT
,
UPDATE
,和
DELETE
statements. Although the
QSqlTableModel
class 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.
這些類提供對 SQL 數據庫的訪問。
| QSql | 包含用於整個 Qt SQL 模塊的雜項標識符 |
| QSqlDatabase | 處理數據庫連接 |
| QSqlDriver | Abstract base class for accessing specific SQL databases |
| QSqlDriverCreator | Template class that provides a SQL driver factory for a specific driver type |
| QSqlDriverCreatorBase | The base class for SQL driver factories |
| QSqlError | SQL 數據庫錯誤信息 |
| QSqlField | 操縱 SQL 數據庫錶和視圖中的字段 |
| QSqlIndex | Functions to manipulate and describe database indexes |
| QSqlQuery | 執行和操縱 SQL 語句的手段 |
| QSqlQueryModel | Read-only data model for SQL result sets |
| QSqlRecord | 封裝數據庫記錄 |
| QSqlRelationalTableModel | Editable data model for a single database table, with foreign key support |
| QSqlResult | Abstract interface for accessing data from specific SQL databases |
| QSqlTableModel | Editable data model for a single database table |
SQL 類分為 3 層:
This comprises the classes QSqlDriver , QSqlDriverCreator , QSqlDriverCreatorBase , QSqlDriverPlugin ,和 QSqlResult .
This layer provides the low-level bridge between the specific databases and the SQL API layer. See SQL 數據庫驅動程序 瞭解更多信息。
These classes provide access to databases. Connections are made using the QSqlDatabase class. Database interaction is achieved by using the QSqlQuery class. In addition to QSqlDatabase and QSqlQuery , the SQL API layer is supported by QSqlError , QSqlField , QSqlIndex ,和 QSqlRecord .
These classes link the data from a database to data-aware widgets. They include QSqlQueryModel , QSqlTableModel ,和 QSqlRelationalTableModel . These classes are designed to work with Qt's 模型/視圖框架 .
注意, QCoreApplication object must be instantiated before using any of these classes.