Qt 4.8
|
The QSqlQueryModel class provides a read-only data model for SQL result sets. More...
#include <qsqlquerymodel.h>
Public Functions | |
bool | canFetchMore (const QModelIndex &parent=QModelIndex()) const |
Returns true if it is possible to read more rows from the database. More... | |
virtual void | clear () |
Clears the model and releases any acquired resource. More... | |
int | columnCount (const QModelIndex &parent=QModelIndex()) const |
Reimplemented Function More... | |
QVariant | data (const QModelIndex &item, int role=Qt::DisplayRole) const |
Returns the value for the specified item and role. More... | |
void | fetchMore (const QModelIndex &parent=QModelIndex()) |
Fetches more rows from a database. More... | |
QVariant | headerData (int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const |
Returns the header data for the given role in the section of the header with the specified orientation. More... | |
bool | insertColumns (int column, int count, const QModelIndex &parent=QModelIndex()) |
Inserts count columns into the model at position column. More... | |
QSqlError | lastError () const |
Returns information about the last error that occurred on the database. More... | |
QSqlQueryModel (QObject *parent=0) | |
Creates an empty QSqlQueryModel with the given parent. More... | |
QSqlQuery | query () const |
Returns the QSqlQuery associated with this model. More... | |
QSqlRecord | record (int row) const |
Returns the record containing information about the fields of the current query. More... | |
QSqlRecord | record () const |
Returns an empty record containing information about the fields of the current query. More... | |
bool | removeColumns (int column, int count, const QModelIndex &parent=QModelIndex()) |
Removes count columns from the model starting from position column. More... | |
int | rowCount (const QModelIndex &parent=QModelIndex()) const |
If the database supports returning the size of a query (see QSqlDriver::hasFeature()), the number of rows of the current query is returned. More... | |
bool | setHeaderData (int section, Qt::Orientation orientation, const QVariant &value, int role=Qt::EditRole) |
Sets the caption for a horizontal header for the specified role to value. More... | |
void | setQuery (const QSqlQuery &query) |
Resets the model and sets the data provider to be the given query. More... | |
void | setQuery (const QString &query, const QSqlDatabase &db=QSqlDatabase()) |
Executes the query query for the given database connection db. More... | |
virtual | ~QSqlQueryModel () |
Destroys the object and frees any allocated resources. More... | |
Public Functions inherited from QAbstractTableModel | |
bool | dropMimeData (const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) |
Reimplemented Function More... | |
QModelIndex | index (int row, int column, const QModelIndex &parent=QModelIndex()) const |
Returns the index of the data in row and column with parent. More... | |
QAbstractTableModel (QObject *parent=0) | |
Constructs an abstract table model for the given parent. More... | |
~QAbstractTableModel () | |
Destroys the abstract table model. More... | |
Public Functions inherited from QAbstractItemModel | |
virtual QModelIndex | buddy (const QModelIndex &index) const |
Returns a model index for the buddy of the item represented by index. More... | |
virtual Qt::ItemFlags | flags (const QModelIndex &index) const |
Returns the item flags for the given index. More... | |
bool | hasIndex (int row, int column, const QModelIndex &parent=QModelIndex()) const |
Returns true if the model returns a valid QModelIndex for row and column with parent, otherwise returns false. More... | |
bool | insertColumn (int column, const QModelIndex &parent=QModelIndex()) |
Inserts a single column before the given column in the child items of the parent specified. More... | |
bool | insertRow (int row, const QModelIndex &parent=QModelIndex()) |
Inserts a single row before the given row in the child items of the parent specified. More... | |
virtual bool | insertRows (int row, int count, const QModelIndex &parent=QModelIndex()) |
On models that support this, inserts count rows into the model before the given row. More... | |
virtual QMap< int, QVariant > | itemData (const QModelIndex &index) const |
Returns a map with values for all predefined roles in the model for the item at the given index. More... | |
virtual QModelIndexList | match (const QModelIndex &start, int role, const QVariant &value, int hits=1, Qt::MatchFlags flags=Qt::MatchFlags(Qt::MatchStartsWith|Qt::MatchWrap)) const |
Returns a list of indexes for the items in the column of the start index where data stored under the given role matches the specified value. More... | |
virtual QMimeData * | mimeData (const QModelIndexList &indexes) const |
Returns an object that contains serialized items of data corresponding to the list of indexes specified. More... | |
virtual QStringList | mimeTypes () const |
Returns a list of MIME types that can be used to describe a list of model indexes. More... | |
QAbstractItemModel (QObject *parent=0) | |
Constructs an abstract item model with the given parent. More... | |
bool | removeColumn (int column, const QModelIndex &parent=QModelIndex()) |
Removes the given column from the child items of the parent specified. More... | |
bool | removeRow (int row, const QModelIndex &parent=QModelIndex()) |
Removes the given row from the child items of the parent specified. More... | |
virtual bool | removeRows (int row, int count, const QModelIndex &parent=QModelIndex()) |
On models that support this, removes count rows starting with the given row under parent parent from the model. More... | |
const QHash< int, QByteArray > & | roleNames () const |
Returns the model's role names. More... | |
virtual bool | setData (const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) |
Sets the role data for the item at index to value. More... | |
virtual bool | setItemData (const QModelIndex &index, const QMap< int, QVariant > &roles) |
Sets the role data for the item at index to the associated value in roles, for every Qt::ItemDataRole. More... | |
void | setSupportedDragActions (Qt::DropActions) |
Sets the supported drag actions for the items in the model. More... | |
QModelIndex | sibling (int row, int column, const QModelIndex &idx) const |
Returns the sibling at row and column for the item at index, or an invalid QModelIndex if there is no sibling at that location. More... | |
virtual void | sort (int column, Qt::SortOrder order=Qt::AscendingOrder) |
Sorts the model by column in the given order. More... | |
virtual QSize | span (const QModelIndex &index) const |
Returns the row and column span of the item represented by index. More... | |
Qt::DropActions | supportedDragActions () const |
Returns the actions supported by the data in this model. More... | |
virtual Qt::DropActions | supportedDropActions () const |
Returns the drop actions supported by this model. More... | |
virtual | ~QAbstractItemModel () |
Destroys the abstract item model. More... | |
Public Functions inherited from QObject | |
bool | blockSignals (bool b) |
If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More... | |
const QObjectList & | children () const |
Returns a list of child objects. More... | |
bool | connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const |
bool | disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0) |
bool | disconnect (const QObject *receiver, const char *member=0) |
void | dumpObjectInfo () |
Dumps information about signal connections, etc. More... | |
void | dumpObjectTree () |
Dumps a tree of children to the debug output. More... | |
QList< QByteArray > | dynamicPropertyNames () const |
Returns the names of all properties that were dynamically added to the object using setProperty(). More... | |
virtual bool | event (QEvent *) |
This virtual function receives events to an object and should return true if the event e was recognized and processed. More... | |
virtual bool | eventFilter (QObject *, QEvent *) |
Filters events if this object has been installed as an event filter for the watched object. More... | |
template<typename T > | |
T | findChild (const QString &aName=QString()) const |
Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More... | |
template<typename T > | |
QList< T > | findChildren (const QString &aName=QString()) const |
Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More... | |
template<typename T > | |
QList< T > | findChildren (const QRegExp &re) const |
bool | inherits (const char *classname) const |
Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More... | |
void | installEventFilter (QObject *) |
Installs an event filter filterObj on this object. More... | |
bool | isWidgetType () const |
Returns true if the object is a widget; otherwise returns false. More... | |
void | killTimer (int id) |
Kills the timer with timer identifier, id. More... | |
virtual const QMetaObject * | metaObject () const |
Returns a pointer to the meta-object of this object. More... | |
void | moveToThread (QThread *thread) |
Changes the thread affinity for this object and its children. More... | |
QString | objectName () const |
QObject * | parent () const |
Returns a pointer to the parent object. More... | |
QVariant | property (const char *name) const |
Returns the value of the object's name property. More... | |
Q_INVOKABLE | QObject (QObject *parent=0) |
Constructs an object with parent object parent. More... | |
void | removeEventFilter (QObject *) |
Removes an event filter object obj from this object. More... | |
void | setObjectName (const QString &name) |
void | setParent (QObject *) |
Makes the object a child of parent. More... | |
bool | setProperty (const char *name, const QVariant &value) |
Sets the value of the object's name property to value. More... | |
void | setUserData (uint id, QObjectUserData *data) |
bool | signalsBlocked () const |
Returns true if signals are blocked; otherwise returns false. More... | |
int | startTimer (int interval) |
Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More... | |
QThread * | thread () const |
Returns the thread in which the object lives. More... | |
QObjectUserData * | userData (uint id) const |
virtual | ~QObject () |
Destroys the object, deleting all its child objects. More... | |
Protected Functions | |
QModelIndex | indexInQuery (const QModelIndex &item) const |
Returns the index of the value in the database result set for the given item in the model. More... | |
QSqlQueryModel (QSqlQueryModelPrivate &dd, QObject *parent=0) | |
virtual void | queryChange () |
This virtual function is called whenever the query changes. More... | |
void | setLastError (const QSqlError &error) |
Protected function which allows derived classes to set the value of the last error that occurred on the database to error. More... | |
Protected Functions inherited from QAbstractTableModel | |
QAbstractTableModel (QAbstractItemModelPrivate &dd, QObject *parent) | |
Constructs an abstract table model with dd and the given parent. More... | |
Protected Functions inherited from QAbstractItemModel | |
void | beginInsertColumns (const QModelIndex &parent, int first, int last) |
Begins a column insertion operation. More... | |
void | beginInsertRows (const QModelIndex &parent, int first, int last) |
Begins a row insertion operation. More... | |
bool | beginMoveColumns (const QModelIndex &sourceParent, int sourceFirst, int sourceLast, const QModelIndex &destinationParent, int destinationColumn) |
Begins a column move operation. More... | |
bool | beginMoveRows (const QModelIndex &sourceParent, int sourceFirst, int sourceLast, const QModelIndex &destinationParent, int destinationRow) |
Begins a row move operation. More... | |
void | beginRemoveColumns (const QModelIndex &parent, int first, int last) |
Begins a column removal operation. More... | |
void | beginRemoveRows (const QModelIndex &parent, int first, int last) |
Begins a row removal operation. More... | |
void | beginResetModel () |
Begins a model reset operation. More... | |
void | changePersistentIndex (const QModelIndex &from, const QModelIndex &to) |
Changes the QPersistentModelIndex that is equal to the given from model index to the given to model index. More... | |
void | changePersistentIndexList (const QModelIndexList &from, const QModelIndexList &to) |
Changes the QPersistentModelIndexes that is equal to the indexes in the given from model index list to the given to model index list. More... | |
QModelIndex | createIndex (int row, int column, void *data=0) const |
Creates a model index for the given row and column with the internal pointer ptr. More... | |
QModelIndex | createIndex (int row, int column, int id) const |
Use QModelIndex QAbstractItemModel::createIndex(int row, int column, quint32 id) instead. More... | |
QModelIndex | createIndex (int row, int column, quint32 id) const |
Creates a model index for the given row and column with the internal identifier, id. More... | |
bool | decodeData (int row, int column, const QModelIndex &parent, QDataStream &stream) |
void | encodeData (const QModelIndexList &indexes, QDataStream &stream) const |
void | endInsertColumns () |
Ends a column insertion operation. More... | |
void | endInsertRows () |
Ends a row insertion operation. More... | |
void | endMoveColumns () |
Ends a column move operation. More... | |
void | endMoveRows () |
Ends a row move operation. More... | |
void | endRemoveColumns () |
Ends a column removal operation. More... | |
void | endRemoveRows () |
Ends a row removal operation. More... | |
void | endResetModel () |
Completes a model reset operation. More... | |
QModelIndexList | persistentIndexList () const |
Returns the list of indexes stored as persistent indexes in the model. More... | |
QAbstractItemModel (QAbstractItemModelPrivate &dd, QObject *parent=0) | |
void | reset () |
Resets the model to its original state in any attached views. More... | |
void | setRoleNames (const QHash< int, QByteArray > &roleNames) |
Sets the model's role names to roleNames. More... | |
Protected Functions inherited from QObject | |
virtual void | childEvent (QChildEvent *) |
This event handler can be reimplemented in a subclass to receive child events. More... | |
virtual void | connectNotify (const char *signal) |
This virtual function is called when something has been connected to signal in this object. More... | |
virtual void | customEvent (QEvent *) |
This event handler can be reimplemented in a subclass to receive custom events. More... | |
virtual void | disconnectNotify (const char *signal) |
This virtual function is called when something has been disconnected from signal in this object. More... | |
QObject (QObjectPrivate &dd, QObject *parent=0) | |
int | receivers (const char *signal) const |
Returns the number of receivers connected to the signal. More... | |
QObject * | sender () const |
Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More... | |
int | senderSignalIndex () const |
virtual void | timerEvent (QTimerEvent *) |
This event handler can be reimplemented in a subclass to receive timer events for the object. More... | |
Additional Inherited Members | |
Public Slots inherited from QAbstractItemModel | |
virtual void | revert () |
Lets the model know that it should discard cached information. More... | |
virtual bool | submit () |
Lets the model know that it should submit cached information to permanent storage. More... | |
Public Slots inherited from QObject | |
void | deleteLater () |
Schedules this object for deletion. More... | |
Signals inherited from QAbstractItemModel | |
void | columnsAboutToBeInserted (const QModelIndex &parent, int first, int last) |
This signal is emitted just before columns are inserted into the model. More... | |
void | columnsAboutToBeMoved (const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationColumn) |
This signal is emitted just before columns are moved within the model. More... | |
void | columnsAboutToBeRemoved (const QModelIndex &parent, int first, int last) |
This signal is emitted just before columns are removed from the model. More... | |
void | columnsInserted (const QModelIndex &parent, int first, int last) |
This signal is emitted after columns have been inserted into the model. More... | |
void | columnsMoved (const QModelIndex &parent, int start, int end, const QModelIndex &destination, int column) |
This signal is emitted after columns have been moved within the model. More... | |
void | columnsRemoved (const QModelIndex &parent, int first, int last) |
This signal is emitted after columns have been removed from the model. More... | |
void | dataChanged (const QModelIndex &topLeft, const QModelIndex &bottomRight) |
This signal is emitted whenever the data in an existing item changes. More... | |
void | headerDataChanged (Qt::Orientation orientation, int first, int last) |
This signal is emitted whenever a header is changed. More... | |
void | layoutAboutToBeChanged () |
This signal is emitted just before the layout of a model is changed. More... | |
void | layoutChanged () |
This signal is emitted whenever the layout of items exposed by the model has changed; for example, when the model has been sorted. More... | |
void | modelAboutToBeReset () |
This signal is emitted when reset() is called, before the model's internal state (e. More... | |
void | modelReset () |
This signal is emitted when reset() is called, after the model's internal state (e. More... | |
void | rowsAboutToBeInserted (const QModelIndex &parent, int first, int last) |
This signal is emitted just before rows are inserted into the model. More... | |
void | rowsAboutToBeMoved (const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationRow) |
This signal is emitted just before rows are moved within the model. More... | |
void | rowsAboutToBeRemoved (const QModelIndex &parent, int first, int last) |
This signal is emitted just before rows are removed from the model. More... | |
void | rowsInserted (const QModelIndex &parent, int first, int last) |
This signal is emitted after rows have been inserted into the model. More... | |
void | rowsMoved (const QModelIndex &parent, int start, int end, const QModelIndex &destination, int row) |
This signal is emitted after rows have been moved within the model. More... | |
void | rowsRemoved (const QModelIndex &parent, int first, int last) |
This signal is emitted after rows have been removed from the model. More... | |
Signals inherited from QObject | |
void | destroyed (QObject *=0) |
This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More... | |
Static Public Functions inherited from QObject | |
static bool | connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection) |
Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More... | |
static bool | connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection) |
static bool | disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member) |
Disconnects signal in object sender from method in object receiver. More... | |
static bool | disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member) |
static uint | registerUserData () |
static QString | tr (const char *sourceText, const char *comment=0, int n=-1) |
static QString | trUtf8 (const char *sourceText, const char *comment=0, int n=-1) |
Static Public Variables inherited from QObject | |
static const QMetaObject | staticMetaObject |
This variable stores the meta-object for the class. More... | |
Protected Slots inherited from QAbstractItemModel | |
void | resetInternalData () |
This slot is called just after the internal data of a model is cleared while it is being reset. More... | |
Protected Variables inherited from QObject | |
QScopedPointer< QObjectData > | d_ptr |
Static Protected Variables inherited from QObject | |
static const QMetaObject | staticQtMetaObject |
Related Functions inherited from QObject | |
T | qFindChildqFindChildren (const QObject *obj, const QString &name)() |
QList< T > | qFindChildrenqFindChildren (const QObject *obj, const QString &name)() |
QList< T > | qFindChildrenqFindChildren (const QObject *obj, const QRegExp ®Exp)() |
T * | qobject_cast (QObject *object) |
QObjectList | |
void * | qt_find_obj_child (QObject *parent, const char *type, const QString &name) |
Returns a pointer to the object named name that inherits type and with a given parent. More... | |
The QSqlQueryModel class provides a read-only data model for SQL result sets.
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:
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:
The code snippet above extracts the salary
field from record 4 in the result set of the query SELECT * from employee
. Assuming that salary
is column 2, we can rewrite the last line as follows:
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 sql/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.
Definition at line 59 of file qsqlquerymodel.h.
|
explicit |
Creates an empty QSqlQueryModel with the given parent.
Definition at line 153 of file qsqlquerymodel.cpp.
|
virtual |
Destroys the object and frees any allocated resources.
Definition at line 170 of file qsqlquerymodel.cpp.
|
protected |
Definition at line 160 of file qsqlquerymodel.cpp.
|
virtual |
Returns true if it is possible to read more rows from the database.
This only affects databases that don't report back the size of a query (see QSqlDriver::hasFeature()).
parent should always be an invalid QModelIndex.
Reimplemented from QAbstractItemModel.
Definition at line 214 of file qsqlquerymodel.cpp.
|
virtual |
Clears the model and releases any acquired resource.
Reimplemented in QSqlRelationalTableModel, and QSqlTableModel.
Definition at line 413 of file qsqlquerymodel.cpp.
Referenced by QSqlTableModel::clear().
|
virtual |
Reimplemented Function
Implements QAbstractItemModel.
Definition at line 243 of file qsqlquerymodel.cpp.
Referenced by QSqlTableModel::revertRow(), setHeaderData(), and QSqlTableModel::setRecord().
|
virtual |
Returns the value for the specified item and role.
If item is out of bounds or if an error occurred, an invalid QVariant is returned.
Implements QAbstractItemModel.
Reimplemented in QSqlRelationalTableModel, and QSqlTableModel.
Definition at line 257 of file qsqlquerymodel.cpp.
Referenced by QSqlTableModel::data(), and record().
|
virtual |
Fetches more rows from a database.
This only affects databases that don't report back the size of a query (see QSqlDriver::hasFeature()).
To force fetching of the entire result set, you can use the following:
parent should always be an invalid QModelIndex.
Reimplemented from QAbstractItemModel.
Definition at line 192 of file qsqlquerymodel.cpp.
Referenced by setQuery().
|
virtual |
Returns the header data for the given role in the section of the header with the specified orientation.
Reimplemented from QAbstractItemModel.
Reimplemented in QSqlTableModel.
Definition at line 285 of file qsqlquerymodel.cpp.
Referenced by QSqlTableModel::headerData().
|
protected |
Returns the index of the value in the database result set for the given item in the model.
The return value is identical to item if no columns or rows have been inserted, removed, or moved around.
Returns an invalid model index if item is out of bounds or if item does not point to a value in the result set.
Definition at line 608 of file qsqlquerymodel.cpp.
Referenced by data(), headerData(), and QSqlTableModel::indexInQuery().
|
virtual |
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.
Returns true if column is within bounds; otherwise returns false.
By default, inserted columns are empty. To fill them with data, reimplement data() and handle any inserted column separately:
Reimplemented from QAbstractItemModel.
Definition at line 543 of file qsqlquerymodel.cpp.
QSqlError QSqlQueryModel::lastError | ( | ) | const |
Returns information about the last error that occurred on the database.
Definition at line 470 of file qsqlquerymodel.cpp.
Referenced by QSqlTableModel::select().
QSqlQuery QSqlQueryModel::query | ( | ) | const |
Returns the QSqlQuery associated with this model.
Definition at line 458 of file qsqlquerymodel.cpp.
Referenced by QSqlTableModel::select(), QSqlRelationalTableModel::selectStatement(), QSqlTableModel::selectStatement(), and setQuery().
|
protectedvirtual |
This virtual function is called whenever the query changes.
The default implementation does nothing.
query() returns the new query.
Definition at line 312 of file qsqlquerymodel.cpp.
Referenced by setQuery().
QSqlRecord QSqlQueryModel::record | ( | int | row | ) | const |
Returns the record containing information about the fields of the current query.
If row is the index of a valid row, the record will be populated with values from that row.
If the model is not initialized, an empty record will be returned.
Definition at line 498 of file qsqlquerymodel.cpp.
Referenced by QRelation::populateDictionary().
QSqlRecord QSqlQueryModel::record | ( | ) | const |
Returns an empty record containing information about the fields of the current query.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
If the model is not initialized, an empty record will be returned.
Definition at line 523 of file qsqlquerymodel.cpp.
|
virtual |
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.
Removing columns effectively hides them. It does not affect the underlying QSqlQuery.
Returns true if the columns were removed; otherwise returns false.
Reimplemented from QAbstractItemModel.
Reimplemented in QSqlTableModel, and QSqlRelationalTableModel.
Definition at line 578 of file qsqlquerymodel.cpp.
|
virtual |
If the database supports returning the size of a query (see QSqlDriver::hasFeature()), the number of rows of the current query is returned.
Otherwise, returns the number of rows currently cached on the client.
parent should always be an invalid QModelIndex.
Implements QAbstractItemModel.
Reimplemented in QSqlTableModel.
Definition at line 235 of file qsqlquerymodel.cpp.
Referenced by QSqlTableModel::rowCount().
|
virtual |
Sets the caption for a horizontal header for the specified role to value.
This is useful if the model is used to display data in a view (e.g., QTableView).
Returns true if orientation is Qt::Horizontal 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.
Definition at line 439 of file qsqlquerymodel.cpp.
|
protected |
Protected function which allows derived classes to set the value of the last error that occurred on the database to error.
Definition at line 482 of file qsqlquerymodel.cpp.
void QSqlQueryModel::setQuery | ( | const QSqlQuery & | query | ) |
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().
lastError() can be used to retrieve verbose information if there was an error setting the query.
Definition at line 329 of file qsqlquerymodel.cpp.
Referenced by setQuery(), and QSqlTableModel::setQuery().
void QSqlQueryModel::setQuery | ( | const QString & | query, |
const QSqlDatabase & | db = QSqlDatabase() |
||
) |
Executes the query query for the given database connection db.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
If no database (or an invalid database) is specified, the default connection is used.
lastError() can be used to retrieve verbose information if there was an error setting the query.
Example:
Definition at line 405 of file qsqlquerymodel.cpp.