Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions | ![]() |
The QSqlQueryModel class provides a read only data model for SQL result sets. More...
#include <QSqlQueryModel>
Inherits QAbstractTableModel.
Inherited by QSqlTableModel.
The QSqlQueryModel class provides a read only data model for SQL result sets.
QSqlQueryModel is a data model that provides data from a QSqlQuery. The QSqlQuery has to be valid and may not be forward-only.
QSqlQueryModel 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 QSqlQueryModel 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.
Returns the header data for the given role in the section of the header with the specified orientation.
Reimplemented from QAbstractItemModel.
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 QSqlQueryModel::data().
Example:
QVariant MyModel::data(const QModelIndex &item, int role) const { if (item.column() == myNewlyInsertedColumn) { return "My calculated value"; } return QSqlQueryModel::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 in the database. If row points to a valid row, the record will be populated with values from that row.
If the model is not initialized, en empty record will be returned.
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.
Sets the caption for the header with the given orientation to the specified value.
It returns true if role is QAbstractItemModel::DisplayRole and the section refers to a valid section; 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().
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Convenience method, executes the query query for the given connection db. If no database is specified, the default connection is used.
Copyright © 2004 Trolltech. | Trademarks | Qt 4.0.0-tp2 |