<class name="QSqlQueryModel" doc="/** <p>The <a href="QSqlQueryModel.html#QSqlQueryModel(com.trolltech.qt.core.QObject)"><tt>QSqlQueryModel</tt></a> class provides a read-only data model for SQL result sets.</p> <p><a href="QSqlQueryModel.html#QSqlQueryModel(com.trolltech.qt.core.QObject)"><tt>QSqlQueryModel</tt></a> is a high-level interface for executing SQL statements and traversing the result set. It is built on top of the lower-level <a href="QSqlQuery.html"><tt>QSqlQuery</tt></a> and can be used to provide data to view classes such as <a href="%2E%2E/gui/QTableView.html"><tt>QTableView</tt></a>. For example:</p> <pre> QSqlQueryModel *model = new QSqlQueryModel; model-&gt;setQuery(&quot;SELECT name, salary FROM employee&quot;); model-&gt;setHeaderData(0, Qt::Horizontal, tr(&quot;Name&quot;)); model-&gt;setHeaderData(1, Qt::Horizontal, tr(&quot;Salary&quot;)); QTableView *view = new QTableView; view-&gt;setModel(model); view-&gt;show();</pre> <p>We set the model's query, then we set up the labels displayed in the view header.</p> <p><a href="QSqlQueryModel.html#QSqlQueryModel(com.trolltech.qt.core.QObject)"><tt>QSqlQueryModel</tt></a> can also be used to access a database programmatically, without binding it to a view:</p> <pre> QSqlQueryModel model; model.setQuery(&quot;SELECT * FROM employee&quot;); int salary = model.record(4).value(&quot;salary&quot;).toInt();</pre> <p>The code snippet above extracts the <tt>salary</tt> field from record 4 in the result set of the query <tt>SELECT * from employee</tt>. Assuming that <tt>salary</tt> is column 2, we can rewrite the last line as follows:</p> <pre> int salary = model.data(model.index(4, 2)).toInt();</pre> <p>The model is read-only by default. To make it read-write, you must subclass it and reimplement <a href="%2E%2E/core/%2E%2E/core/QAbstractItemModel.html#setData(com.trolltech.qt.core.QModelIndex, java.lang.Object, int)"><tt>setData</tt></a> and <a href="%2E%2E/core/%2E%2E/core/QAbstractItemModel.html#flags(com.trolltech.qt.core.QModelIndex)"><tt>flags</tt></a>. Another option is to use <a href="QSqlTableModel.html"><tt>QSqlTableModel</tt></a>, which provides a read-write model based on a single database table.</p> <p>The sql/querymodel</tt> example illustrates how to use <a href="QSqlQueryModel.html#QSqlQueryModel(com.trolltech.qt.core.QObject)"><tt>QSqlQueryModel</tt></a> to display the result of a query. It also shows how to subclass <a href="QSqlQueryModel.html#QSqlQueryModel(com.trolltech.qt.core.QObject)"><tt>QSqlQueryModel</tt></a> to customize the contents of the data before showing it to the user, and how to create a read-write model based on <a href="QSqlQueryModel.html#QSqlQueryModel(com.trolltech.qt.core.QObject)"><tt>QSqlQueryModel</tt></a>.</p> <p>If the database doesn't return the amount of selected rows in a query, the model will fetch rows incrementally. See <a href="QSqlQueryModel.html#fetchMore(com.trolltech.qt.core.QModelIndex)"><tt>fetchMore</tt></a> for more information.</p> @see <a href="QSqlTableModel.html"><tt>QSqlTableModel</tt></a> @see <a href="QSqlRelationalTableModel.html"><tt>QSqlRelationalTableModel</tt></a> @see <a href="QSqlQuery.html"><tt>QSqlQuery</tt></a> @see <a href="%2E%2E/model-view-programming.html">Model/View Programming</tt></a> @see Query Model Example</tt> */"> <signal name="protected final void dataChanged(com.trolltech.qt.core.QModelIndex topLeft, com.trolltech.qt.core.QModelIndex bottomRight)" doc="/** <p>This signal is emitted whenever the data in an existing item changes. The affected items are those between <tt>topLeft</tt> and <tt>bottomRight</tt> inclusive (of the same parent).</p> <p>Note that this signal must be emitted explicitly when reimplementing the <a href="%2E%2E/core/%2E%2E/core/QAbstractItemModel.html#setData(com.trolltech.qt.core.QModelIndex, java.lang.Object, int)"><tt>setData</tt></a> function.</p> <dl> <dt><b>Compatible Slot Signatures:</b></dt> <dd><tt>void mySlot(com.trolltech.qt.core.QModelIndex topLeft, com.trolltech.qt.core.QModelIndex bottomRight)</tt></dd> <dd><tt>void mySlot(com.trolltech.qt.core.QModelIndex topLeft)</tt></dd> <dd><tt>void mySlot()</tt></dd> </dl> <dl> <dt><b>See Also:</b></dt> <dd><a href="QSqlQueryModel.html#headerDataChanged(com.trolltech.qt.core.Qt.Orientation, int, int)"><tt>headerDataChanged</tt></a>, <a href="%2E%2E/core/%2E%2E/core/QAbstractItemModel.html#setData(com.trolltech.qt.core.QModelIndex, java.lang.Object, int)"><tt>setData</tt></a>, <a href="QSqlQueryModel.html#layoutChanged()"><tt>layoutChanged</tt></a></dd> </dl> */"/> <signal name="protected final void headerDataChanged(com.trolltech.qt.core.Qt.Orientation orientation, int first, int last)" doc="/** <p>This signal is emitted whenever a header is changed. The <tt>orientation</tt> indicates whether the horizontal or vertical header has changed. The sections in the header from the <tt>first</tt> to the <tt>last</tt> need to be updated.</p> <p>Note that this signal must be emitted explicitly when reimplementing the <a href="QSqlQueryModel.html#setHeaderData(int, com.trolltech.qt.core.Qt.Orientation, java.lang.Object, int)"><tt>setHeaderData</tt></a> function.</p> <p>If you are changing the number of columns or rows you don't need to emit this signal, but use the begin/end functions.</p> <dl> <dt><b>Compatible Slot Signatures:</b></dt> <dd><tt>void mySlot(com.trolltech.qt.core.Qt.Orientation orientation, int first, int last)</tt></dd> <dd><tt>void mySlot(com.trolltech.qt.core.Qt.Orientation orientation, int first)</tt></dd> <dd><tt>void mySlot(com.trolltech.qt.core.Qt.Orientation orientation)</tt></dd> <dd><tt>void mySlot()</tt></dd> </dl> <dl> <dt><b>See Also:</b></dt> <dd><a href="QSqlQueryModel.html#headerData(int, com.trolltech.qt.core.Qt.Orientation, int)"><tt>headerData</tt></a>, <a href="QSqlQueryModel.html#setHeaderData(int, com.trolltech.qt.core.Qt.Orientation, java.lang.Object, int)"><tt>setHeaderData</tt></a>, <a href="QSqlQueryModel.html#dataChanged(com.trolltech.qt.core.QModelIndex, com.trolltech.qt.core.QModelIndex)"><tt>dataChanged</tt></a></dd> </dl> */"/> <signal name="protected final void layoutAboutToBeChanged()" doc="/** <p>This signal is emitted just before the layout of a model is changed. Components connected to this signal use it to adapt to changes in the model's layout.</p> <p>Subclasses should update any persistent model indexes after emitting <a href="QSqlQueryModel.html#layoutAboutToBeChanged()"><tt>layoutAboutToBeChanged</tt></a>.</p> <dl> <dt><b>Compatible Slot Signature:</b></dt> <dd><tt>void mySlot()</tt></dd> </dl> <dl> <dt><b>See Also:</b></dt> <dd><a href="QSqlQueryModel.html#layoutChanged()"><tt>layoutChanged</tt></a>, <a href="%2E%2E/core/%2E%2E/core/QAbstractItemModel.html#changePersistentIndex(com.trolltech.qt.core.QModelIndex, com.trolltech.qt.core.QModelIndex)"><tt>changePersistentIndex</tt></a></dd> </dl> */"/> <signal name="protected final void layoutChanged()" doc="/** <p>This signal is emitted whenever the layout of items exposed by the model has changed; for example, when the model has been sorted. When this signal is received by a view, it should update the layout of items to reflect this change.</p> <p>When subclassing <a href="%2E%2E/core/%2E%2E/core/QAbstractItemModel.html#QAbstractItemModel(com.trolltech.qt.core.QObject)"><tt>QAbstractItemModel</tt></a> or <a href="%2E%2E/gui/QAbstractProxyModel.html"><tt>QAbstractProxyModel</tt></a>, ensure that you emit <a href="QSqlQueryModel.html#layoutAboutToBeChanged()"><tt>layoutAboutToBeChanged</tt></a> before changing the order of items or altering the structure of the data you expose to views, and emit <a href="QSqlQueryModel.html#layoutChanged()"><tt>layoutChanged</tt></a> after changing the layout.</p> <p>Subclasses should update any persistent model indexes before emitting <a href="QSqlQueryModel.html#layoutChanged()"><tt>layoutChanged</tt></a>.</p> <dl> <dt><b>Compatible Slot Signature:</b></dt> <dd><tt>void mySlot()</tt></dd> </dl> <dl> <dt><b>See Also:</b></dt> <dd><a href="QSqlQueryModel.html#layoutAboutToBeChanged()"><tt>layoutAboutToBeChanged</tt></a>, <a href="QSqlQueryModel.html#dataChanged(com.trolltech.qt.core.QModelIndex, com.trolltech.qt.core.QModelIndex)"><tt>dataChanged</tt></a>, <a href="QSqlQueryModel.html#headerDataChanged(com.trolltech.qt.core.Qt.Orientation, int, int)"><tt>headerDataChanged</tt></a>, <a href="%2E%2E/core/%2E%2E/core/QAbstractItemModel.html#reset()"><tt>reset</tt></a>, <a href="%2E%2E/core/%2E%2E/core/QAbstractItemModel.html#changePersistentIndex(com.trolltech.qt.core.QModelIndex, com.trolltech.qt.core.QModelIndex)"><tt>changePersistentIndex</tt></a></dd> </dl> */"/> <method name="public QSqlQueryModel(com.trolltech.qt.core.QObject parent)" doc="/** <p>Creates an empty <a href="QSqlQueryModel.html#QSqlQueryModel(com.trolltech.qt.core.QObject)"><tt>QSqlQueryModel</tt></a> with the given <tt>parent</tt>.</p> */"/> <method name="public QSqlQueryModel()" doc="/** <p>Equivalent to <a href="QSqlQueryModel.html#QSqlQueryModel(com.trolltech.qt.core.QObject)"><tt>QSqlQueryModel</tt></a>(0). */"/> <method name="protected com.trolltech.qt.core.QModelIndex indexInQuery(com.trolltech.qt.core.QModelIndex item)" doc="/** <p>Returns the index of the value in the database result set for the given <tt>item</tt> in the model.</p> <p>The return value is identical to <tt>item</tt> if no columns or rows have been inserted, removed, or moved around.</p> <p>Returns an invalid model index if <tt>item</tt> is out of bounds or if <tt>item</tt> does not point to a value in the result set.</p> @see <tt>QSqlTableModel::indexInQuery</tt> @see <a href="QSqlQueryModel.html#insertColumns(int, int, com.trolltech.qt.core.QModelIndex)"><tt>insertColumns</tt></a> @see <a href="QSqlQueryModel.html#removeColumns(int, int, com.trolltech.qt.core.QModelIndex)"><tt>removeColumns</tt></a> */"/> <method name="public final com.trolltech.qt.sql.QSqlError lastError()" doc="/** <p>Returns information about the last error that occurred on the database.</p> @see <a href="QSqlQueryModel.html#setLastError(com.trolltech.qt.sql.QSqlError)"><tt>setLastError</tt></a> */"/> <method name="public final com.trolltech.qt.sql.QSqlQuery query()" doc="/** <p>Returns the <a href="QSqlQuery.html"><tt>QSqlQuery</tt></a> associated with this model.</p> @see <a href="QSqlQueryModel.html#setQuery(java.lang.String, com.trolltech.qt.sql.QSqlDatabase)"><tt>setQuery</tt></a> */"/> <method name="public final com.trolltech.qt.sql.QSqlRecord record(int row)" doc="/** <p>Returns the record containing information about the fields of the current query. If <tt>row</tt> is the index of a valid row, the record will be populated with values from that row.</p> <p>If the model is not initialized, an empty record will be returned.</p> @see <tt>QSqlRecord::isEmpty</tt> */"/> <method name="public final com.trolltech.qt.sql.QSqlRecord record()" doc="/** <p>Returns an empty record containing information about the fields of the current query.</p> <p>If the model is not initialized, an empty record will be returned.</p> @see <tt>QSqlRecord::isEmpty</tt> */"/> <method name="protected final void setLastError(com.trolltech.qt.sql.QSqlError error)" doc="/** <p>Protected function which allows derived classes to set the value of the last error that occurred on the database to <tt>error</tt>.</p> @see <a href="QSqlQueryModel.html#lastError()"><tt>lastError</tt></a> */"/> <method name="public void setQuery(com.trolltech.qt.sql.QSqlQuery query)" doc="/** <p>Resets the model and sets the data provider to be the given <tt>query</tt>. Note that the query must be active and must not be isForwardOnly().</p> <p><a href="QSqlQueryModel.html#lastError()"><tt>lastError</tt></a> can be used to retrieve verbose information if there was an error setting the query.</p> @see <a href="QSqlQueryModel.html#query()"><tt>query</tt></a> @see <tt>QSqlQuery::isActive</tt> @see <tt>QSqlQuery::setForwardOnly</tt> @see <a href="QSqlQueryModel.html#lastError()"><tt>lastError</tt></a> */"/> <method name="public final void setQuery(java.lang.String query, com.trolltech.qt.sql.QSqlDatabase db)" doc="/** <p>Executes the query <tt>query</tt> for the given database connection <tt>db</tt>. If no database is specified, the default connection is used.</p> <p><a href="QSqlQueryModel.html#lastError()"><tt>lastError</tt></a> can be used to retrieve verbose information if there was an error setting the query.</p> <p>Example:</p> <pre> QSqlQueryModel model; model.setQuery(&quot;select * from MyTable&quot;); if (model.lastError().isValid()) qDebug() &lt;&lt; model.lastError();</pre> @see <a href="QSqlQueryModel.html#query()"><tt>query</tt></a> @see <a href="QSqlQueryModel.html#queryChange()"><tt>queryChange</tt></a> @see <a href="QSqlQueryModel.html#lastError()"><tt>lastError</tt></a> */"/> <method name="public final void setQuery(java.lang.String query)" doc="/** <p>Equivalent to <a href="QSqlQueryModel.html#setQuery(java.lang.String, com.trolltech.qt.sql.QSqlDatabase)"><tt>setQuery</tt></a>(<tt>query</tt>, QSqlDatabase()). */"/> <method name="public boolean canFetchMore(com.trolltech.qt.core.QModelIndex parent)" doc="/** <p>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()).</p> <p><tt>parent</tt> should always be an invalid QModelIndex.</p> @see <a href="QSqlQueryModel.html#fetchMore(com.trolltech.qt.core.QModelIndex)"><tt>fetchMore</tt></a> */"/> <method name="public final boolean canFetchMore()" doc="/** <p>Equivalent to <a href="QSqlQueryModel.html#canFetchMore(com.trolltech.qt.core.QModelIndex)"><tt>canFetchMore</tt></a>(QModelIndex()). */"/> <method name="public void clear()" doc="/** <p>Clears the model and releases any acquired resource.</p> */"/> <method name="public int columnCount(com.trolltech.qt.core.QModelIndex parent)" doc="/** <p>This function is reimplemented for internal reasons.</p> */"/> <method name="public final int columnCount()" doc="/** <p>Equivalent to <a href="QSqlQueryModel.html#columnCount(com.trolltech.qt.core.QModelIndex)"><tt>columnCount</tt></a>(QModelIndex()). */"/> <method name="public java.lang.Object data(com.trolltech.qt.core.QModelIndex item, int role)" doc="/** <p>Returns the value for the specified <tt>item</tt> and <tt>role</tt>.</p> <p>If <tt>item</tt> is out of bounds or if an error occurred, an invalid <a href="%2E%2E/porting4.html#qvariant"><tt>QVariant</tt></a> is returned.</p> @see <a href="QSqlQueryModel.html#lastError()"><tt>lastError</tt></a> */"/> <method name="public final java.lang.Object data(com.trolltech.qt.core.QModelIndex item)" doc="/** <p>Equivalent to <a href="QSqlQueryModel.html#data(com.trolltech.qt.core.QModelIndex, int)">data</tt></a>(<tt>item</tt>, Qt::DisplayRole). */"/> <method name="public void fetchMore(com.trolltech.qt.core.QModelIndex parent)" doc="/** <p>Fetches more rows from a database. This only affects databases that don't report back the size of a query (see QSqlDriver::hasFeature()).</p> <p>To force fetching of the entire database, you can use the following:</p> <pre> while (myModel-&gt;canFetchMore()) myModel-&gt;fetchMore();</pre> <p><tt>parent</tt> should always be an invalid QModelIndex.</p> @see <a href="QSqlQueryModel.html#canFetchMore(com.trolltech.qt.core.QModelIndex)"><tt>canFetchMore</tt></a> */"/> <method name="public final void fetchMore()" doc="/** <p>Equivalent to <a href="QSqlQueryModel.html#fetchMore(com.trolltech.qt.core.QModelIndex)"><tt>fetchMore</tt></a>(QModelIndex()). */"/> <method name="public java.lang.Object headerData(int section, com.trolltech.qt.core.Qt.Orientation orientation, int role)" doc="/** <p>Returns the header data for the given <tt>role</tt> in the <tt>section</tt> of the header with the specified <tt>orientation</tt>.</p> @see <a href="QSqlQueryModel.html#setHeaderData(int, com.trolltech.qt.core.Qt.Orientation, java.lang.Object, int)"><tt>setHeaderData</tt></a> */"/> <method name="public final java.lang.Object headerData(int section, com.trolltech.qt.core.Qt.Orientation orientation)" doc="/** <p>Equivalent to <a href="QSqlQueryModel.html#headerData(int, com.trolltech.qt.core.Qt.Orientation, int)"><tt>headerData</tt></a>(<tt>section</tt>, <tt>orientation</tt>, Qt::DisplayRole). */"/> <method name="public boolean insertColumns(int column, int count, com.trolltech.qt.core.QModelIndex parent)" doc="/** <p>Inserts <tt>count</tt> columns into the model at position <tt>column</tt>. The <tt>parent</tt> parameter must always be an invalid QModelIndex, since the model does not support parent-child relationships.</p> <p>Returns true if <tt>column</tt> is within bounds; otherwise returns false.</p> <p>By default, inserted columns are empty. To fill them with data, reimplement <a href="QSqlQueryModel.html#data(com.trolltech.qt.core.QModelIndex, int)"><tt>data</tt></a> and handle any inserted column separately:</p> <pre> QVariant MyModel::data(const QModelIndex &amp;item, int role) const { if (item.column() == m_specialColumnNo) { <span class="comment">// handle column separately</span> } return QSqlQueryModel::data(item, role); }</pre> @see <a href="QSqlQueryModel.html#removeColumns(int, int, com.trolltech.qt.core.QModelIndex)"><tt>removeColumns</tt></a> */"/> <method name="public final boolean insertColumns(int column, int count)" doc="/** <p>Equivalent to <a href="QSqlQueryModel.html#insertColumns(int, int, com.trolltech.qt.core.QModelIndex)"><tt>insertColumns</tt></a>(<tt>column</tt>, <tt>count</tt>, QModelIndex()). */"/> <method name="protected void queryChange()" doc="/** <p>This virtual function is called whenever the query changes. The default implementation does nothing.</p> <p><a href="QSqlQueryModel.html#query()"><tt>query</tt></a> returns the new query.</p> @see <a href="QSqlQueryModel.html#query()"><tt>query</tt></a> @see <a href="QSqlQueryModel.html#setQuery(java.lang.String, com.trolltech.qt.sql.QSqlDatabase)"><tt>setQuery</tt></a> */"/> <method name="public boolean removeColumns(int column, int count, com.trolltech.qt.core.QModelIndex parent)" doc="/** <p>Removes <tt>count</tt> columns from the model starting from position <tt>column</tt>. The <tt>parent</tt> parameter must always be an invalid QModelIndex, since the model does not support parent-child relationships.</p> <p>Removing columns effectively hides them. It does not affect the underlying <a href="QSqlQuery.html"><tt>QSqlQuery</tt></a>.</p> <p>Returns true if the columns were removed; otherwise returns false.</p> */"/> <method name="public final boolean removeColumns(int column, int count)" doc="/** <p>Equivalent to <a href="QSqlQueryModel.html#removeColumns(int, int, com.trolltech.qt.core.QModelIndex)"><tt>removeColumns</tt></a>(<tt>column</tt>, <tt>count</tt>, QModelIndex()). */"/> <method name="public int rowCount(com.trolltech.qt.core.QModelIndex parent)" doc="/** <p>If the database supports returning the size of a query (see QSqlDriver::hasFeature()), the amount of rows of the current query is returned. Otherwise, returns the amount of rows currently cached on the client.</p> <p><tt>parent</tt> should always be an invalid QModelIndex.</p> @see <a href="QSqlQueryModel.html#canFetchMore(com.trolltech.qt.core.QModelIndex)"><tt>canFetchMore</tt></a> @see <tt>QSqlDriver::hasFeature</tt> */"/> <method name="public final int rowCount()" doc="/** <p>Equivalent to <a href="QSqlQueryModel.html#rowCount(com.trolltech.qt.core.QModelIndex)"><tt>rowCount</tt></a>(QModelIndex()). */"/> <method name="public boolean setHeaderData(int section, com.trolltech.qt.core.Qt.Orientation orientation, java.lang.Object value, int role)" doc="/** <p>Sets the caption for a horizontal header for the specified <tt>role</tt> to <tt>value</tt>. This is useful if the model is used to display data in a view (e.g&#x2e;, <a href="%2E%2E/gui/QTableView.html"><tt>QTableView</tt></a>).</p> <p>Returns true if <tt>orientation</tt> is Qt::Horizontal and the <tt>section</tt> refers to a valid section; otherwise returns false.</p> <p>Note that this function cannot be used to modify values in the database since the model is read-only.</p> @see <a href="QSqlQueryModel.html#headerData(int, com.trolltech.qt.core.Qt.Orientation, int)"><tt>headerData</tt></a> @see <a href="QSqlQueryModel.html#data(com.trolltech.qt.core.QModelIndex, int)"><tt>data</tt></a> */"/> <method name="public final boolean setHeaderData(int section, com.trolltech.qt.core.Qt.Orientation orientation, java.lang.Object value)" doc="/** <p>Equivalent to <a href="QSqlQueryModel.html#setHeaderData(int, com.trolltech.qt.core.Qt.Orientation, java.lang.Object, int)"><tt>setHeaderData</tt></a>(<tt>section</tt>, <tt>orientation</tt>, <tt>value</tt>, Qt::EditRole). */"/> </class>