Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions | ![]() |
The QSqlModel class provides a read only data model for SQL result sets. More...
#include <QSqlModel>
Inherits QAbstractTableModel.
Inherited by QSqlTableModel.
The QSqlModel class provides a read only data model for SQL result sets.
QSqlModel is a data model that provides data from a QSqlQuery. The QSqlQuery has to be valid and may not be forward-only.
QSqlModel model; model.setQuery("SELECT FORENAME, SURNAME, ID FROM TEST");
The model is read-only by default, to make it read-write, it is neccessary to reimplement the setData() and isEditable() methods.
QSqlTableModel is a convenience subclass which allows manipulating a database table.
See also QSqlTableModel and QSqlQuery.
Creates an empty QSqlModel and sets the parent to parent.
Destroys the object and frees any allocated resources.
Clears the model and releases all aquired resources
Returns the value for the specified item and role.
For items with type QModelIndex::HorizontalHeader, the name of the database field is returned. This can be overridden by setData().
For items with type QModelIndex::VerticalHeader, the index of the row is returned.
An invalid QVariant is returned if item is out of bounds or if an error occured.
Reimplemented from QAbstractItemModel.
See also setData() and lastError().
Returns the index of the value in the database result set for the given item for situations where the row and column of an item in the model does not map to the same row and column in the database result set.
Returns an invalid model index if item is out of bounds or if item does not point to a value in the result set.
Inserts count columns into the model at position column. The parent parameter must always be an invalid QModelIndex, since the model does not support parent-child relationships.
To populate the newly inserted columns with data, you must reimplement QSqlModel::data().
Example:
QVariant MyModel::data(const QModelIndex &item, int role) const { if (item.column() == myNewlyInsertedColumn) { return "My calculated value"; } return QSqlModel::data(item, role); }
Returns true if column is within bounds; otherwise returns false.
Returns information about the last error that occurred on the database.
Returns the QSqlQuery that is associated with this model.
See also setQuery().
Returns the record containing information about the fields that are currently displayed. Returns an empty record if the model has not yet been initialized.
Removes count columns from the model starting from position column. The parent parameter must always be an invalid QModelIndex, since the model does not support parent-child relationships.
Note that removing columns does not affect the underlying QSqlQuery, it will just hide the columns.
Returns true if the columns were removed; otherwise returns false.
This function is used to set the caption for the horizontal header of a column to value.
It returns true if role is QAbstractItemModel::Display and index is of type QModelIndex::HorizontalHeader and points to a valid column; otherwise returns false.
Note that this function cannot be used to modify values in the database since the model is read-only.
Reimplemented from QAbstractItemModel.
See also data().
Protected function which allows derived classes to set the value of the last error that occurred on the database to error.
See also lastError().
Resets the model and sets the data provider to be the given query. Note that the query must be active and must not be isForwardOnly().
See also query(), QSqlQuery::isActive(), and QSqlQuery::setForwardOnly().
Copyright © 2004 Trolltech. | Trademarks | Qt 4.0.0-tp1 |