| qsqlquerymodel.cpp |
!
\class QSqlQueryModel
\brief The QSqlQueryModel class provides a read-only data model for SQL
result sets.
\ingroup database
\inmodule QtSql
QSqlQueryModel is a high-level interface for executing SQL
statements and traversing the result set. It is built on top of
the lower-level QSqlQuery and can be used to provide data to
view classes such as QTableView. For example:
\snippet sqldatabase/sqldatabase_snippet.cpp 16
We set the model's query, then we set up the labels displayed in
the view header.
QSqlQueryModel can also be used to access a database
programmatically, without binding it to a view:
\snippet sqldatabase/sqldatabase.cpp 21
The code snippet above extracts the \c salary field from record 4 in
the result set of the \c SELECT query. Since \c salary is the 2nd
column (or column index 1), we can rewrite the last line as follows:
\snippet sqldatabase/sqldatabase.cpp 22
The model is read-only by default. To make it read-write, you
must subclass it and reimplement setData() and flags(). Another
option is to use QSqlTableModel, which provides a read-write
model based on a single database table.
The \l{querymodel} example illustrates how to use
QSqlQueryModel to display the result of a query. It also shows
how to subclass QSqlQueryModel to customize the contents of the
data before showing it to the user, and how to create a
read-write model based on QSqlQueryModel.
If the database doesn't return the number of selected rows in
a query, the model will fetch rows incrementally.
See fetchMore() for more information.
\sa QSqlTableModel, QSqlRelationalTableModel, QSqlQuery,
{Model/View Programming}, {Query Model Example}
|
18927 |
- |
| qsqlquerymodel.h |
|
2961 |
- |
| qsqlquerymodel_p.h |
|
4504 |
- |
| qsqlrelationaldelegate.cpp |
!
\class QSqlRelationalDelegate
\inmodule QtSql
\brief The QSqlRelationalDelegate class provides a delegate that is used to
display and edit data from a QSqlRelationalTableModel.
Unlike the default delegate, QSqlRelationalDelegate provides a
combobox for fields that are foreign keys into other tables. To
use the class, simply call QAbstractItemView::setItemDelegate()
on the view with an instance of QSqlRelationalDelegate:
\snippet relationaltablemodel/relationaltablemodel.cpp 4
The \l{relationaltablemodel}{Relational Table Model} example
(shown below) illustrates how to use QSqlRelationalDelegate in
conjunction with QSqlRelationalTableModel to provide tables with
foreign key support.
\image relationaltable.png {The user is able to edit a foreign key in a relational table}
\sa QSqlRelationalTableModel, {Model/View Programming}
|
1934 |
- |
| qsqlrelationaldelegate.h |
|
4339 |
- |
| qsqlrelationaltablemodel.cpp |
!
\class QSqlRelation
\inmodule QtSql
\brief The QSqlRelation class stores information about an SQL foreign key.
QSqlRelation is a helper class for QSqlRelationalTableModel. See
QSqlRelationalTableModel::setRelation() and
QSqlRelationalTableModel::relation() for details.
\sa QSqlRelationalTableModel, QSqlRelationalDelegate,
{Relational Table Model Example}
|
25259 |
- |
| qsqlrelationaltablemodel.h |
|
2637 |
- |
| qsqltablemodel.cpp |
! \internal
Populates our record with values.
|
43495 |
- |
| qsqltablemodel.h |
|
3507 |
- |
| qsqltablemodel_p.h |
|
4508 |
- |