Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions | ![]() |
The QSqlTableModel class provides an editable data model for a single database table. More...
#include <QSqlTableModel>
Inherits QSqlQueryModel.
Inherited by QSqlRelationalTableModel.
The QSqlTableModel class provides an editable data model for a single database table.
QSqlTableModel is a data model that provides data from a database table. By default, the model can be edited.
QSqlTableModel model; model.setTable("MYTABLE"); model.select();
Before the table can be used, a table name has to be set. After that, it is possible to set filters with setFilter() or modify the sort order with setSort().
After all the desired options have been set, select() has to be called to populate the model with data.
This enum type describes which strategy to choose when editing values in the database.
QSqlTableModel::OnFieldChange | All changes to the model will be applied immediately to the database. |
QSqlTableModel::OnRowChange | Changes will be applied when the current row changes. |
QSqlTableModel::OnManualSubmit | All changes will be cached in the model until either submitChanges() or revertAll() is invoked. |
Creates an empty QSqlTableModel and sets the parent to parent and the database connection to db. If db is not valid, the default database connection will be used.
Destroys the object and frees any allocated resources.
This signal is emitted before the row row is deleted.
This signal is emitted before a new row is inserted. The values that are about to be inserted are stored in record and can be modified before they will be inserted.
This signal is emitted before the row row is updated with the values from record.
Note that only values that are marked as generated will be updated. The generated flag can be set with QSqlRecord::setGenerated() and checked with QSqlRecord::isGenerated().
See also QSqlRecord::isGenerated().
Returns the data for the item at position idx for the role role. Returns an invalid variant if idx is out of bounds.
Reimplemented from QAbstractItemModel.
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 a pointer to the used QSqlDatabase or 0 if no database was set.
Deletes the given row in the model. Returns true if the row was deleted; otherwise returns false.
Returns the current edit strategy.
See also EditStrategy and setEditStrategy().
Returns the index of the field fieldName.
Returns the currently set filter.
See also setFilter() and select().
Returns the header data for the given role in the section of the header with the specified orientation.
Inserts the values values into the database table. Returns true if the values could be inserted, otherwise false. Error information can be retrieved with lastError().
See also lastError().
// TODO document manual updates Inserts an empty row at position row. Note that parent has to be invalid, since this model does not support parent-child relations.
Note that only one row can be inserted at a time, so count should always be 1.
The primeInsert() signal will be emitted, so the newly inserted values can be initialized.
Returns false if the parameters are out of bounds, otherwise true.
Reimplemented from QAbstractItemModel.
See also primeInsert().
Returns true if the value at the index index is dirty, otherwise false. Dirty values are values that were modified in the model but not yet written into the database.
If index is invalid or points to a non-existing row, false is returned.
Returns a SQL 'ORDER BY' statement based on the currently set sort order.
See also sort().
Returns the primary key for the current table, or an empty QSqlIndex if the table is not set or has no primary key.
This signal is emitted when an insertion is initiated in the given row. The record parameter can be written to (since it is a reference), for example to populate some fields with default values.
Removes the given column from the parent model.
See also removeRows() and TODO.
Removes count rows starting at row. Since this model does not support hierarchical structures, parent must be an invalid model index.
Emits the beforeDelete() signal before a row is deleted.
Returns true if all rows could be removed, otherwise false. Detailed error information can be retrieved with lastError().
Reimplemented from QAbstractItemModel.
See also removeColumns().
Revert all pending changes.
Reverts all changes for the current row.
Populates the model with data from the table that was set via setTable(), using the specified filter and sort condition.
See also setTable(), setFilter(), and sort().
Returns a SQL SELECT statement.
Sets the data for the item index for the role role to value. Depending on the edit strategy, the value might be applied to the database at once or cached in the model.
Returns true if the value could be set or false on error, for example if index is out of bounds.
Reimplemented from QAbstractItemModel.
See also editStrategy(), data(), submitChanges(), and revertRow().
Sets the strategy for editing values in the database to strategy. This will revert all pending changes.
See also EditStrategy and editStrategy().
Sets the current filter to filter. Note that no new records are selected. To select new records, use select(). The filter will apply to any subsequent select() calls.
The filter is a SQL WHERE clause without the keyword 'WHERE', e.g. name='Harry' which will be processed by the DBMS.
See also filter() and select().
Protected method to allow subclasses to set the primary key to key.
Sets the values at the specified row to the values of record. Returns false if not all the values could be set, otherwise true.
See also record().
Sets the sort oder for column to order. This does not affect the current data, to refresh the data using the new sort order, call select().
See also select(), sort(), isSortable(), and orderByStatement().
Sets the table to tableName. Does not select data from the table, but fetches its field information.
To populate the model with the table's data, call select().
See also select(), setFilter(), and sort().
Sorts the data by column with the sort order order. This will immediately select data, use setSort() to set a sort order without populating the model with data.
See also setSort(), isSortable(), select(), and orderByStatement().
Submits all pending changes and returns true on success.
See also lastError().
Returns the name of the currently selected table.
Updates the row row in the currently active database table with the values from values.
Note that only values that have the generated-flag set are updated. The generated-flag can be set with QSqlRecord::setGenerated() and tested with QSqlRecord::isGenerated().
See also QSqlRecord::isGenerated().
Copyright © 2004 Trolltech. | Trademarks | Qt 4.0.0-tp2 |