<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # QSqlQueryModel Class Reference ## [[QtSql](index.htm) module] 該QSqlQueryModel類為SQL結果集的只讀數據模型。[More...](#details) 繼承[QAbstractTableModel](qabstracttablemodel.html)。 通過繼承[QSqlTableModel](qsqltablemodel.html)。 ### Methods * `__init__ (self, QObject?parent?=?None)` * `bool canFetchMore (self, QModelIndex?parent?=?QModelIndex())` * `clear (self)` * `int columnCount (self, QModelIndex?parent?=?QModelIndex())` * `QVariant data (self, QModelIndex?item, int?role?=?Qt.DisplayRole)` * `fetchMore (self, QModelIndex?parent?=?QModelIndex())` * `QVariant headerData (self, int?section, Qt.Orientation?orientation, int?role?=?Qt.DisplayRole)` * `QModelIndex indexInQuery (self, QModelIndex?item)` * `bool insertColumns (self, int?column, int?count, QModelIndex?parent?=?QModelIndex())` * `QSqlError lastError (self)` * `QSqlQuery query (self)` * `queryChange (self)` * `QSqlRecord record (self, int?row)` * `QSqlRecord record (self)` * `bool removeColumns (self, int?column, int?count, QModelIndex?parent?=?QModelIndex())` * `int rowCount (self, QModelIndex?parent?=?QModelIndex())` * `bool setHeaderData (self, int?section, Qt.Orientation?orientation, QVariant?value, int?role?=?Qt.EditRole)` * `setLastError (self, QSqlError?error)` * `setQuery (self, QSqlQuery?query)` * `setQuery (self, QString?query, QSqlDatabase?db?=?QSqlDatabase())` * * * ## Detailed Description 該QSqlQueryModel類為SQL結果集的只讀數據模型。 QSqlQueryModel是用于執行SQL語句并遍歷結果集一個高層次的接口。它是建立在較低級別的頂[QSqlQuery](qsqlquery.html)并且可以用來提供數據可以看到類如[QTableView](qtableview.html)。例如: ``` QSqlQueryModel *model = new QSqlQueryModel; model->setQuery("SELECT name, salary FROM employee"); model->setHeaderData(0, [Qt](qt.html).Horizontal, tr("Name")); model->setHeaderData(1, [Qt](qt.html).Horizontal, tr("Salary")); [QTableView](qtableview.html) *view = new [QTableView](qtableview.html); view->setModel(model); view->show(); ``` 我們建立模型的查詢,然后我們設置視圖中的標題顯示的標籤。 QSqlQueryModel也可以用來訪問數據庫編程,不綁定到一個視圖: ``` QSqlQueryModel model; model.setQuery("SELECT * FROM employee"); int salary = model.record(4).value("salary").toInt(); ``` 上面的代碼片段中提取`salary`從查詢的結果集記錄4場`SELECT * from employee`。假設`salary`是第2列,我們可以重寫最后一行,如下所示: ``` int salary = model.data(model.index(4, 2)).toInt(); ``` 該模型是只讀的默認。為了使讀寫,你必須繼承它,并重新實現[setData](qabstractitemmodel.html#setData)()和[flags](qabstractitemmodel.html#flags)( ) 。另一個選項是使用[QSqlTableModel](qsqltablemodel.html),它提供了基于單個數據庫表中的讀 - 寫的模式。 該[sql/querymodel](index.htm)示例說明了如何使用QSqlQueryModel以顯示查詢的結果。它也顯示了如何繼承QSqlQueryModel顯示給用戶之前自定義數據的內容,以及如何創建基于QSqlQueryModel一個讀寫模式。 如果數據庫沒有返回在查詢中選擇的行數,該模型將逐步獲取行。看[fetchMore](qsqlquerymodel.html#fetchMore)( )獲取更多信息。 * * * ## Method Documentation ``` QSqlQueryModel.__init__ (self, QObject?parent?=?None) ``` 該_parent_的說法,如果不是沒有,原因_self_通過Qt的,而不是PyQt的擁有。 創建一個空的[QSqlQueryModel](qsqlquerymodel.html)用給定的_parent_。 ``` bool QSqlQueryModel.canFetchMore (self, QModelIndex?parent?=?QModelIndex()) ``` 從重新實現[QAbstractItemModel.canFetchMore](qabstractitemmodel.html#canFetchMore)( ) 。 返回True如果有可能從數據庫中讀取更多的行。這只會影響數據庫不報到查詢的尺寸(見[QSqlDriver.hasFeature](qsqldriver.html#hasFeature)())。 _parent_應始終為無效[QModelIndex](qmodelindex.html)。 這個函數是Qt 4.1中引入。 **See also** [fetchMore](qsqlquerymodel.html#fetchMore)( ) 。 ``` QSqlQueryModel.clear (self) ``` 清除模型,并釋放任何收購資源。 ``` int QSqlQueryModel.columnCount (self, QModelIndex?parent?=?QModelIndex()) ``` 從重新實現[QAbstractItemModel.columnCount](qabstractitemmodel.html#columnCount)( ) 。 ``` QVariant QSqlQueryModel.data (self, QModelIndex?item, int?role?=?Qt.DisplayRole) ``` 從重新實現[QAbstractItemModel.data](qabstractitemmodel.html#data)( ) 。 返回值指定_item_和_role_。 If _item_超出范圍,或者如果發生錯誤,無效的[QVariant](qvariant.html)返回。 **See also** [lastError](qsqlquerymodel.html#lastError)( ) 。 ``` QSqlQueryModel.fetchMore (self, QModelIndex?parent?=?QModelIndex()) ``` 從重新實現[QAbstractItemModel.fetchMore](qabstractitemmodel.html#fetchMore)( ) 。 獲取從數據庫中多個行。這只會影響數據庫不報到查詢的尺寸(見[QSqlDriver.hasFeature](qsqldriver.html#hasFeature)())。 要強制整個結果集的抓取,你可以使用以下命令: ``` while (myModel->canFetchMore()) myModel->fetchMore(); ``` _parent_應始終為無效[QModelIndex](qmodelindex.html)。 這個函數是Qt 4.1中引入。 **See also** [canFetchMore](qsqlquerymodel.html#canFetchMore)( ) 。 ``` QVariant QSqlQueryModel.headerData (self, int?section, Qt.Orientation?orientation, int?role?=?Qt.DisplayRole) ``` 從重新實現[QAbstractItemModel.headerData](qabstractitemmodel.html#headerData)( ) 。 返回頭數據為給定的_role_在_section_用指定的標頭_orientation_。 **See also** [setHeaderData](qsqlquerymodel.html#setHeaderData)( ) 。 ``` QModelIndex QSqlQueryModel.indexInQuery (self, QModelIndex?item) ``` [ 返回在給定的數據庫中的結果集的值的索引_item_在模型中。 返回值是相同的_item_如果已經插入任何行或列,刪除或移動了。 返回一個無效的模型索引,如果_item_超出范圍或_item_不指向結果集中的值。 ](qmodelindex.html) [**See also**](qmodelindex.html) [QSqlTableModel.indexInQuery](qsqltablemodel.html#indexInQuery)( )[insertColumns](qsqlquerymodel.html#insertColumns)()和[removeColumns](qsqlquerymodel.html#removeColumns)( ) 。 ``` bool QSqlQueryModel.insertColumns (self, int?column, int?count, QModelIndex?parent?=?QModelIndex()) ``` 從重新實現[QAbstractItemModel.insertColumns](qabstractitemmodel.html#insertColumns)( ) 。 Inserts _count_列到模型的位置_column_。該_parent_參數必須始終是一個無效的[QModelIndex](qmodelindex.html),因為該模型不支持父子關系。 返回True如果_column_是在一定范圍內,否則返回False 。 默認情況下,插入的列是空的。為了填補他們的數據,重新實現[data](qsqlquerymodel.html#data)( )并單獨處理任何插入的列: ``` [QVariant](qvariant.html) MyModel.data(const [QModelIndex](qmodelindex.html) &item, int role) const { if (item.column() == m_specialColumnNo) { // handle column separately } return [QSqlQueryModel](qsqlquerymodel.html).data(item, role); } ``` **See also** [removeColumns](qsqlquerymodel.html#removeColumns)( ) 。 ``` QSqlError QSqlQueryModel.lastError (self) ``` [ 返回有關數據庫上發生的最后一個錯誤信息。 ](qsqlerror.html) [**See also**](qsqlerror.html) [setLastError](qsqlquerymodel.html#setLastError)()和[query](qsqlquerymodel.html#query)( ) 。 ``` QSqlQuery QSqlQueryModel.query (self) ``` [](qsqlquery.html) [返回](qsqlquery.html)[QSqlQuery](qsqlquery.html)與此模型相關。 **See also** [setQuery](qsqlquerymodel.html#setQuery)( ) 。 ``` QSqlQueryModel.queryChange (self) ``` 這個虛函數被調用時查詢改變。默認實現不執行任何操作。 [query](qsqlquerymodel.html#query)( )返回新的查詢。 **See also** [query](qsqlquerymodel.html#query)()和[setQuery](qsqlquerymodel.html#setQuery)( ) 。 ``` QSqlRecord QSqlQueryModel.record (self, int?row) ``` [ 返回有關當前查詢的字段包含記錄信息。如果_row_是一個有效的行的索引,該記錄將被填入該行的值。 如果模型沒有被初始化,一個空的記錄將被退回。 ](qsqlrecord.html) [**See also**](qsqlrecord.html) [QSqlRecord.isEmpty](qsqlrecord.html#isEmpty)( ) 。 ``` QSqlRecord QSqlQueryModel.record (self) ``` [ 這是一個重載函數。 返回有關當前查詢的字段為空的記錄包含的信息。 如果模型沒有被初始化,一個空的記錄將被退回。 ](qsqlrecord.html) [**See also**](qsqlrecord.html) [QSqlRecord.isEmpty](qsqlrecord.html#isEmpty)( ) 。 ``` bool QSqlQueryModel.removeColumns (self, int?column, int?count, QModelIndex?parent?=?QModelIndex()) ``` 從重新實現[QAbstractItemModel.removeColumns](qabstractitemmodel.html#removeColumns)( ) 。 移除_count_從模型中的列從位置開始_column_。該_parent_參數必須始終是一個無效的[QModelIndex](qmodelindex.html),因為該模型不支持父子關系。 刪除列有效地隱藏它們。它不影響相關[QSqlQuery](qsqlquery.html)。 返回True如果被刪除的列,否則返回False 。 ``` int QSqlQueryModel.rowCount (self, QModelIndex?parent?=?QModelIndex()) ``` 從重新實現[QAbstractItemModel.rowCount](qabstractitemmodel.html#rowCount)( ) 。 如果數據庫支持返回查詢的尺寸(見[QSqlDriver.hasFeature](qsqldriver.html#hasFeature)())時,返回的行的當前查詢的數量。否則,將返回客戶端上當前緩存的行數。 _parent_應始終為無效[QModelIndex](qmodelindex.html)。 這個函數是Qt 4.1中引入。 **See also** [canFetchMore](qsqlquerymodel.html#canFetchMore)()和[QSqlDriver.hasFeature](qsqldriver.html#hasFeature)( ) 。 ``` bool QSqlQueryModel.setHeaderData (self, int?section, Qt.Orientation?orientation, QVariant?value, int?role?=?Qt.EditRole) ``` 從重新實現[QAbstractItemModel.setHeaderData](qabstractitemmodel.html#setHeaderData)( ) 。 設置的標題指定一個水平標題_role_至_value_。如果模型被用來在一個視圖中顯示的數據(例如這是有用的,[QTableView](qtableview.html)) 。 返回True如果_orientation_ is [Qt.Horizontal](qt.html#Orientation-enum)和_section_指的是一個有效的部分,否則返回False 。 注意,該功能不能用于在數據庫中的修改值,因為該模型是只讀的。 **See also** [headerData](qsqlquerymodel.html#headerData)()和[data](qsqlquerymodel.html#data)( ) 。 ``` QSqlQueryModel.setLastError (self, QSqlError?error) ``` 保護功能,允許派生類對設置在數據庫上發生的最后一個錯誤的值_error_。 **See also** [lastError](qsqlquerymodel.html#lastError)( ) 。 ``` QSqlQueryModel.setQuery (self, QSqlQuery?query) ``` 重置模型,并將數據提供給被給定的_query_。請注意,查詢必須處于活動狀態,且不能是isForwardOnly ( ) 。 [lastError](qsqlquerymodel.html#lastError)( )可以用來獲取詳細信息,如果有錯誤設置查詢。 **Note:**調用setQuery ( )將刪除任何插入的列。 **See also** [query](qsqlquerymodel.html#query)( )[QSqlQuery.isActive](qsqlquery.html#isActive)( )[QSqlQuery.setForwardOnly](qsqlquery.html#setForwardOnly)()和[lastError](qsqlquerymodel.html#lastError)( ) 。 ``` QSqlQueryModel.setQuery (self, QString?query, QSqlDatabase?db?=?QSqlDatabase()) ``` 這是一個重載函數。 執行查詢_query_對于給定的數據庫連接_db_。如果沒有指定的數據庫(或無效的數據庫) ,則使用默認連接。 [lastError](qsqlquerymodel.html#lastError)( )可以用來獲取詳細信息,如果有錯誤設置查詢。 例如: ``` [QSqlQueryModel](qsqlquerymodel.html) model; model.setQuery("select * from MyTable"); if (model.lastError().isValid()) qDebug() << model.lastError(); ``` **See also** [query](qsqlquerymodel.html#query)( )[queryChange](qsqlquerymodel.html#queryChange)()和[lastError](qsqlquerymodel.html#lastError)( ) 。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看