Sophie

Sophie

distrib > Mageia > 7 > x86_64 > by-pkgid > 1dd17e0d683ef79b4bb6872bbf359d7f > files > 6420

qt4-doc-4.8.7-26.2.mga7.noarch.rpm

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en_US" lang="en_US">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- qsqlquerymodel.cpp -->
  <title>Qt 4.8: QSqlQueryModel Class Reference</title>
  <link rel="stylesheet" type="text/css" href="style/style.css" />
  <script src="scripts/jquery.js" type="text/javascript"></script>
  <script src="scripts/functions.js" type="text/javascript"></script>
  <link rel="stylesheet" type="text/css" href="style/superfish.css" />
  <link rel="stylesheet" type="text/css" href="style/narrow.css" />
  <!--[if IE]>
<meta name="MSSmartTagsPreventParsing" content="true">
<meta http-equiv="imagetoolbar" content="no">
<![endif]-->
<!--[if lt IE 7]>
<link rel="stylesheet" type="text/css" href="style/style_ie6.css">
<![endif]-->
<!--[if IE 7]>
<link rel="stylesheet" type="text/css" href="style/style_ie7.css">
<![endif]-->
<!--[if IE 8]>
<link rel="stylesheet" type="text/css" href="style/style_ie8.css">
<![endif]-->

<script src="scripts/superfish.js" type="text/javascript"></script>
<script src="scripts/narrow.js" type="text/javascript"></script>

</head>
<body class="" onload="CheckEmptyAndLoadList();">
 <div class="header" id="qtdocheader">
    <div class="content"> 
    <div id="nav-logo">
      <a href="index.html">Home</a></div>
    <a href="index.html" class="qtref"><span>Qt Reference Documentation</span></a>
    <div id="narrowsearch"></div>
    <div id="nav-topright">
      <ul>
        <li class="nav-topright-home"><a href="http://qt.digia.com/">Qt HOME</a></li>
        <li class="nav-topright-dev"><a href="http://qt-project.org/">DEV</a></li>
        <li class="nav-topright-doc nav-topright-doc-active"><a href="http://qt-project.org/doc/">
          DOC</a></li>
        <li class="nav-topright-blog"><a href="http://blog.qt.digia.com/">BLOG</a></li>
      </ul>
    </div>
    <div id="shortCut">
      <ul>
        <li class="shortCut-topleft-inactive"><span><a href="index.html">Qt 4.8</a></span></li>
        <li class="shortCut-topleft-active"><a href="http://qt-project.org/doc/">ALL VERSIONS        </a></li>
      </ul>
     </div>
 <ul class="sf-menu" id="narrowmenu"> 
             <li><a href="#">API Lookup</a> 
                 <ul> 
                     <li><a href="classes.html">Class index</a></li> 
           <li><a href="functions.html">Function index</a></li> 
           <li><a href="modules.html">Modules</a></li> 
           <li><a href="namespaces.html">Namespaces</a></li> 
           <li><a href="qtglobal.html">Global Declarations</a></li> 
           <li><a href="qdeclarativeelements.html">QML elements</a></li> 
             </ul> 
             </li> 
             <li><a href="#">Qt Topics</a> 
                 <ul> 
                        <li><a href="qt-basic-concepts.html">Programming with Qt</a></li>  
                        <li><a href="qtquick.html">Device UIs &amp; Qt Quick</a></li>  
                        <li><a href="qt-gui-concepts.html">UI Design with Qt</a></li>  
                        <li><a href="supported-platforms.html">Supported Platforms</a></li>  
                        <li><a href="technology-apis.html">Qt and Key Technologies</a></li>  
                        <li><a href="best-practices.html">How-To's and Best Practices</a></li>  
              </ul> 
                 </li> 
                 <li><a href="#">Examples</a> 
                     <ul> 
                       <li><a href="all-examples.html">Examples</a></li> 
                       <li><a href="tutorials.html">Tutorials</a></li> 
                       <li><a href="demos.html">Demos</a></li> 
                       <li><a href="qdeclarativeexamples.html">QML Examples</a></li> 
                </ul> 
                     </li> 
                 </ul> 
    </div>
  </div>
  <div class="wrapper">
    <div class="hd">
      <span></span>
    </div>
    <div class="bd group">
      <div class="sidebar">
        <div class="searchlabel">
          Search index:</div>
        <div class="search" id="sidebarsearch">
          <form id="qtdocsearch" action="" onsubmit="return false;">
            <fieldset>
              <input type="text" name="searchstring" id="pageType" value="" />
 <div id="resultdialog"> 
 <a href="#" id="resultclose">Close</a> 
 <p id="resultlinks" class="all"><a href="#" id="showallresults">All</a> | <a href="#" id="showapiresults">API</a> | <a href="#" id="showarticleresults">Articles</a> | <a href="#" id="showexampleresults">Examples</a></p> 
 <p id="searchcount" class="all"><span id="resultcount"></span><span id="apicount"></span><span id="articlecount"></span><span id="examplecount"></span>&nbsp;results:</p> 
 <ul id="resultlist" class="all"> 
 </ul> 
 </div> 
            </fieldset>
          </form>
        </div>
        <div class="box first bottombar" id="lookup">
          <h2 title="API Lookup"><span></span>
            API Lookup</h2>
          <div  id="list001" class="list">
          <ul id="ul001" >
              <li class="defaultLink"><a href="classes.html">Class index</a></li>
              <li class="defaultLink"><a href="functions.html">Function index</a></li>
              <li class="defaultLink"><a href="modules.html">Modules</a></li>
              <li class="defaultLink"><a href="namespaces.html">Namespaces</a></li>
              <li class="defaultLink"><a href="qtglobal.html">Global Declarations</a></li>
              <li class="defaultLink"><a href="qdeclarativeelements.html">QML elements</a></li>
            </ul> 
          </div>
        </div>
        <div class="box bottombar" id="topics">
          <h2 title="Qt Topics"><span></span>
            Qt Topics</h2>
          <div id="list002" class="list">
            <ul id="ul002" >
               <li class="defaultLink"><a href="qt-basic-concepts.html">Programming with Qt</a></li> 
               <li class="defaultLink"><a href="qtquick.html">Device UIs &amp; Qt Quick</a></li> 
               <li class="defaultLink"><a href="qt-gui-concepts.html">UI Design with Qt</a></li> 
               <li class="defaultLink"><a href="supported-platforms.html">Supported Platforms</a></li>  
               <li class="defaultLink"><a href="technology-apis.html">Qt and Key Technologies</a></li> 
               <li class="defaultLink"><a href="best-practices.html">How-To's and Best Practices</a></li> 
            </ul>  
          </div>
        </div>
        <div class="box" id="examples">
          <h2 title="Examples"><span></span>
            Examples</h2>
          <div id="list003" class="list">
        <ul id="ul003">
              <li class="defaultLink"><a href="all-examples.html">Examples</a></li>
              <li class="defaultLink"><a href="tutorials.html">Tutorials</a></li>
              <li class="defaultLink"><a href="demos.html">Demos</a></li>
              <li class="defaultLink"><a href="qdeclarativeexamples.html">QML Examples</a></li>
            </ul> 
          </div>
        </div>
      </div>
      <div class="wrap">
        <div class="toolbar">
          <div class="breadcrumb toolblock">
            <ul>
              <li class="first"><a href="index.html">Home</a></li>
              <!--  Breadcrumbs go here -->
<li><a href="modules.html">Modules</a></li>
<li><a href="qtsql.html">QtSql</a></li>
<li>QSqlQueryModel</li>
            </ul>
          </div>
          <div class="toolbuttons toolblock">
            <ul>
              <li id="smallA" class="t_button">A</li>
              <li id="medA" class="t_button active">A</li>
              <li id="bigA" class="t_button">A</li>
              <li id="print" class="t_button"><a href="javascript:this.print();">
                <span>Print</span></a></li>
            </ul>
        </div>
        </div>
        <div class="content mainContent">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#public-functions">Public Functions</a></li>
<li class="level1"><a href="#protected-functions">Protected Functions</a></li>
<li class="level1"><a href="#details">Detailed Description</a></li>
</ul>
</div>
<h1 class="title">QSqlQueryModel Class Reference</h1>
<!-- $$$QSqlQueryModel-brief -->
<p>The QSqlQueryModel class provides a read-only data model for SQL result sets. <a href="#details">More...</a></p>
<!-- @@@QSqlQueryModel -->
<pre class="cpp"> <span class="preprocessor">#include &lt;QSqlQueryModel&gt;</span></pre><p><b>Inherits: </b><a href="qabstracttablemodel.html">QAbstractTableModel</a>.</p>
<p><b>Inherited by: </b><a href="qsqltablemodel.html">QSqlTableModel</a>.</p>
<ul>
<li><a href="qsqlquerymodel-members.html">List of all members, including inherited members</a></li>
</ul>
<a name="public-functions"></a>
<h2>Public Functions</h2>
<table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qsqlquerymodel.html#QSqlQueryModel">QSqlQueryModel</a></b> ( QObject * <i>parent</i> = 0 )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual </td><td class="memItemRight bottomAlign"><b><a href="qsqlquerymodel.html#dtor.QSqlQueryModel">~QSqlQueryModel</a></b> ()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual void </td><td class="memItemRight bottomAlign"><b><a href="qsqlquerymodel.html#clear">clear</a></b> ()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QSqlError </td><td class="memItemRight bottomAlign"><b><a href="qsqlquerymodel.html#lastError">lastError</a></b> () const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QSqlQuery </td><td class="memItemRight bottomAlign"><b><a href="qsqlquerymodel.html#query">query</a></b> () const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QSqlRecord </td><td class="memItemRight bottomAlign"><b><a href="qsqlquerymodel.html#record">record</a></b> ( int <i>row</i> ) const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QSqlRecord </td><td class="memItemRight bottomAlign"><b><a href="qsqlquerymodel.html#record-2">record</a></b> () const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qsqlquerymodel.html#setQuery">setQuery</a></b> ( const QSqlQuery &amp; <i>query</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qsqlquerymodel.html#setQuery-2">setQuery</a></b> ( const QString &amp; <i>query</i>, const QSqlDatabase &amp; <i>db</i> = QSqlDatabase() )</td></tr>
</table>
<a name="reimplemented-public-functions"></a>
<h2>Reimplemented Public Functions</h2>
<table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> virtual bool </td><td class="memItemRight bottomAlign"><b><a href="qsqlquerymodel.html#canFetchMore">canFetchMore</a></b> ( const QModelIndex &amp; <i>parent</i> = QModelIndex() ) const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual int </td><td class="memItemRight bottomAlign"><b><a href="qsqlquerymodel.html#columnCount">columnCount</a></b> ( const QModelIndex &amp; <i>index</i> = QModelIndex() ) const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual QVariant </td><td class="memItemRight bottomAlign"><b><a href="qsqlquerymodel.html#data">data</a></b> ( const QModelIndex &amp; <i>item</i>, int <i>role</i> = Qt::DisplayRole ) const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual void </td><td class="memItemRight bottomAlign"><b><a href="qsqlquerymodel.html#fetchMore">fetchMore</a></b> ( const QModelIndex &amp; <i>parent</i> = QModelIndex() )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual QVariant </td><td class="memItemRight bottomAlign"><b><a href="qsqlquerymodel.html#headerData">headerData</a></b> ( int <i>section</i>, Qt::Orientation <i>orientation</i>, int <i>role</i> = Qt::DisplayRole ) const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual bool </td><td class="memItemRight bottomAlign"><b><a href="qsqlquerymodel.html#insertColumns">insertColumns</a></b> ( int <i>column</i>, int <i>count</i>, const QModelIndex &amp; <i>parent</i> = QModelIndex() )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual bool </td><td class="memItemRight bottomAlign"><b><a href="qsqlquerymodel.html#removeColumns">removeColumns</a></b> ( int <i>column</i>, int <i>count</i>, const QModelIndex &amp; <i>parent</i> = QModelIndex() )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual int </td><td class="memItemRight bottomAlign"><b><a href="qsqlquerymodel.html#rowCount">rowCount</a></b> ( const QModelIndex &amp; <i>parent</i> = QModelIndex() ) const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual bool </td><td class="memItemRight bottomAlign"><b><a href="qsqlquerymodel.html#setHeaderData">setHeaderData</a></b> ( int <i>section</i>, Qt::Orientation <i>orientation</i>, const QVariant &amp; <i>value</i>, int <i>role</i> = Qt::EditRole )</td></tr>
</table>
<ul>
<li class="fn">2 public functions inherited from <a href="qabstracttablemodel.html#public-functions">QAbstractTableModel</a></li>
<li class="fn">35 public functions inherited from <a href="qabstractitemmodel.html#public-functions">QAbstractItemModel</a></li>
<li class="fn">29 public functions inherited from <a href="qobject.html#public-functions">QObject</a></li>
</ul>
<a name="protected-functions"></a>
<h2>Protected Functions</h2>
<table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> QModelIndex </td><td class="memItemRight bottomAlign"><b><a href="qsqlquerymodel.html#indexInQuery">indexInQuery</a></b> ( const QModelIndex &amp; <i>item</i> ) const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual void </td><td class="memItemRight bottomAlign"><b><a href="qsqlquerymodel.html#queryChange">queryChange</a></b> ()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qsqlquerymodel.html#setLastError">setLastError</a></b> ( const QSqlError &amp; <i>error</i> )</td></tr>
</table>
<ul>
<li class="fn">21 protected functions inherited from <a href="qabstractitemmodel.html#protected-functions">QAbstractItemModel</a></li>
<li class="fn">8 protected functions inherited from <a href="qobject.html#protected-functions">QObject</a></li>
</ul>
<h3>Additional Inherited Members</h3>
<ul>
<li class="fn">1 property inherited from <a href="qobject.html#properties">QObject</a></li>
<li class="fn">2 public slots inherited from <a href="qabstractitemmodel.html#public-slots">QAbstractItemModel</a></li>
<li class="fn">1 public slot inherited from <a href="qobject.html#public-slots">QObject</a></li>
<li class="fn">18 signals inherited from <a href="qabstractitemmodel.html#signals">QAbstractItemModel</a></li>
<li class="fn">1 signal inherited from <a href="qobject.html#signals">QObject</a></li>
<li class="fn">7 static public members inherited from <a href="qobject.html#static-public-members">QObject</a></li>
<li class="fn">1 protected slot inherited from <a href="qabstractitemmodel.html#protected-slots">QAbstractItemModel</a></li>
</ul>
<a name="details"></a>
<!-- $$$QSqlQueryModel-description -->
<div class="descr">
<h2>Detailed Description</h2>
<p>The QSqlQueryModel class provides a read-only data model for SQL result sets.</p>
<p>QSqlQueryModel 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">QSqlQuery</a> and can be used to provide data to view classes such as <a href="qtableview.html">QTableView</a>. For example:</p>
<pre class="cpp">     <span class="type">QSqlQueryModel</span> <span class="operator">*</span>model <span class="operator">=</span> <span class="keyword">new</span> <span class="type">QSqlQueryModel</span>;
     model<span class="operator">-</span><span class="operator">&gt;</span>setQuery(<span class="string">&quot;SELECT name, salary FROM employee&quot;</span>);
     model<span class="operator">-</span><span class="operator">&gt;</span>setHeaderData(<span class="number">0</span><span class="operator">,</span> <span class="type"><a href="qt.html">Qt</a></span><span class="operator">::</span>Horizontal<span class="operator">,</span> tr(<span class="string">&quot;Name&quot;</span>));
     model<span class="operator">-</span><span class="operator">&gt;</span>setHeaderData(<span class="number">1</span><span class="operator">,</span> <span class="type"><a href="qt.html">Qt</a></span><span class="operator">::</span>Horizontal<span class="operator">,</span> tr(<span class="string">&quot;Salary&quot;</span>));

     <span class="type"><a href="qtableview.html">QTableView</a></span> <span class="operator">*</span>view <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qtableview.html">QTableView</a></span>;
     view<span class="operator">-</span><span class="operator">&gt;</span>setModel(model);
     view<span class="operator">-</span><span class="operator">&gt;</span>show();</pre>
<p>We set the model's query, then we set up the labels displayed in the view header.</p>
<p>QSqlQueryModel can also be used to access a database programmatically, without binding it to a view:</p>
<pre class="cpp">     <span class="type">QSqlQueryModel</span> model;
     model<span class="operator">.</span>setQuery(<span class="string">&quot;SELECT * FROM employee&quot;</span>);
     <span class="type">int</span> salary <span class="operator">=</span> model<span class="operator">.</span>record(<span class="number">4</span>)<span class="operator">.</span>value(<span class="string">&quot;salary&quot;</span>)<span class="operator">.</span>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 class="cpp">     <span class="type">int</span> salary <span class="operator">=</span> model<span class="operator">.</span>data(model<span class="operator">.</span>index(<span class="number">4</span><span class="operator">,</span> <span class="number">2</span>))<span class="operator">.</span>toInt();</pre>
<p>The model is read-only by default. To make it read-write, you must subclass it and reimplement <a href="qabstractitemmodel.html#setData">setData</a>() and <a href="qabstractitemmodel.html#flags">flags</a>(). Another option is to use <a href="qsqltablemodel.html">QSqlTableModel</a>, which provides a read-write model based on a single database table.</p>
<p>The <a href="sql-querymodel.html">sql/querymodel</a> 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.</p>
<p>If the database doesn't return the number of selected rows in a query, the model will fetch rows incrementally. See <a href="qsqlquerymodel.html#fetchMore">fetchMore</a>() for more information.</p>
</div>
<p><b>See also </b><a href="qsqltablemodel.html">QSqlTableModel</a>, <a href="qsqlrelationaltablemodel.html">QSqlRelationalTableModel</a>, <a href="qsqlquery.html">QSqlQuery</a>, <a href="model-view-programming.html">Model/View Programming</a>, and <a href="sql-querymodel.html">Query Model Example</a>.</p>
<!-- @@@QSqlQueryModel -->
<div class="func">
<h2>Member Function Documentation</h2>
<!-- $$$QSqlQueryModel[overload1]$$$QSqlQueryModelQObject* -->
<h3 class="fn"><a name="QSqlQueryModel"></a>QSqlQueryModel::<span class="name">QSqlQueryModel</span> ( <span class="type"><a href="qobject.html">QObject</a></span> * <i>parent</i> = 0 )</h3>
<p>Creates an empty <a href="qsqlquerymodel.html">QSqlQueryModel</a> with the given <i>parent</i>.</p>
<!-- @@@QSqlQueryModel -->
<!-- $$$~QSqlQueryModel[overload1]$$$~QSqlQueryModel -->
<h3 class="fn"><a name="dtor.QSqlQueryModel"></a>QSqlQueryModel::<span class="name">~QSqlQueryModel</span> ()<tt> [virtual]</tt></h3>
<p>Destroys the object and frees any allocated resources.</p>
<p><b>See also </b><a href="qsqlquerymodel.html#clear">clear</a>().</p>
<!-- @@@~QSqlQueryModel -->
<!-- $$$canFetchMore[overload1]$$$canFetchMoreconstQModelIndex& -->
<h3 class="fn"><a name="canFetchMore"></a><span class="type">bool</span> QSqlQueryModel::<span class="name">canFetchMore</span> ( const <span class="type"><a href="qmodelindex.html">QModelIndex</a></span> &amp; <i>parent</i> = QModelIndex() ) const<tt> [virtual]</tt></h3>
<p>Reimplemented from <a href="qabstractitemmodel.html#canFetchMore">QAbstractItemModel::canFetchMore</a>().</p>
<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 <a href="qsqldriver.html#hasFeature">QSqlDriver::hasFeature</a>()).</p>
<p><i>parent</i> should always be an invalid <a href="qmodelindex.html">QModelIndex</a>.</p>
<p>This function was introduced in Qt 4.1.</p>
<p><b>See also </b><a href="qsqlquerymodel.html#fetchMore">fetchMore</a>().</p>
<!-- @@@canFetchMore -->
<!-- $$$clear[overload1]$$$clear -->
<h3 class="fn"><a name="clear"></a><span class="type">void</span> QSqlQueryModel::<span class="name">clear</span> ()<tt> [virtual]</tt></h3>
<p>Clears the model and releases any acquired resource.</p>
<!-- @@@clear -->
<!-- $$$columnCount[overload1]$$$columnCountconstQModelIndex& -->
<h3 class="fn"><a name="columnCount"></a><span class="type">int</span> QSqlQueryModel::<span class="name">columnCount</span> ( const <span class="type"><a href="qmodelindex.html">QModelIndex</a></span> &amp; <i>index</i> = QModelIndex() ) const<tt> [virtual]</tt></h3>
<p>Reimplemented from <a href="qabstractitemmodel.html#columnCount">QAbstractItemModel::columnCount</a>().</p>
<!-- @@@columnCount -->
<!-- $$$data[overload1]$$$dataconstQModelIndex&int -->
<h3 class="fn"><a name="data"></a><span class="type"><a href="qvariant.html">QVariant</a></span> QSqlQueryModel::<span class="name">data</span> ( const <span class="type"><a href="qmodelindex.html">QModelIndex</a></span> &amp; <i>item</i>, <span class="type">int</span> <i>role</i> = Qt::DisplayRole ) const<tt> [virtual]</tt></h3>
<p>Reimplemented from <a href="qabstractitemmodel.html#data">QAbstractItemModel::data</a>().</p>
<p>Returns the value for the specified <i>item</i> and <i>role</i>.</p>
<p>If <i>item</i> is out of bounds or if an error occurred, an invalid <a href="qvariant.html">QVariant</a> is returned.</p>
<p><b>See also </b><a href="qsqlquerymodel.html#lastError">lastError</a>().</p>
<!-- @@@data -->
<!-- $$$fetchMore[overload1]$$$fetchMoreconstQModelIndex& -->
<h3 class="fn"><a name="fetchMore"></a><span class="type">void</span> QSqlQueryModel::<span class="name">fetchMore</span> ( const <span class="type"><a href="qmodelindex.html">QModelIndex</a></span> &amp; <i>parent</i> = QModelIndex() )<tt> [virtual]</tt></h3>
<p>Reimplemented from <a href="qabstractitemmodel.html#fetchMore">QAbstractItemModel::fetchMore</a>().</p>
<p>Fetches more rows from a database. This only affects databases that don't report back the size of a query (see <a href="qsqldriver.html#hasFeature">QSqlDriver::hasFeature</a>()).</p>
<p>To force fetching of the entire result set, you can use the following:</p>
<pre class="cpp"> <span class="keyword">while</span> (myModel<span class="operator">-</span><span class="operator">&gt;</span>canFetchMore())
     myModel<span class="operator">-</span><span class="operator">&gt;</span>fetchMore();</pre>
<p><i>parent</i> should always be an invalid <a href="qmodelindex.html">QModelIndex</a>.</p>
<p>This function was introduced in Qt 4.1.</p>
<p><b>See also </b><a href="qsqlquerymodel.html#canFetchMore">canFetchMore</a>().</p>
<!-- @@@fetchMore -->
<!-- $$$headerData[overload1]$$$headerDataintQt::Orientationint -->
<h3 class="fn"><a name="headerData"></a><span class="type"><a href="qvariant.html">QVariant</a></span> QSqlQueryModel::<span class="name">headerData</span> ( <span class="type">int</span> <i>section</i>, <span class="type"><a href="qt.html#Orientation-enum">Qt::Orientation</a></span> <i>orientation</i>, <span class="type">int</span> <i>role</i> = Qt::DisplayRole ) const<tt> [virtual]</tt></h3>
<p>Reimplemented from <a href="qabstractitemmodel.html#headerData">QAbstractItemModel::headerData</a>().</p>
<p>Returns the header data for the given <i>role</i> in the <i>section</i> of the header with the specified <i>orientation</i>.</p>
<p><b>See also </b><a href="qsqlquerymodel.html#setHeaderData">setHeaderData</a>().</p>
<!-- @@@headerData -->
<!-- $$$indexInQuery[overload1]$$$indexInQueryconstQModelIndex& -->
<h3 class="fn"><a name="indexInQuery"></a><span class="type"><a href="qmodelindex.html">QModelIndex</a></span> QSqlQueryModel::<span class="name">indexInQuery</span> ( const <span class="type"><a href="qmodelindex.html">QModelIndex</a></span> &amp; <i>item</i> ) const<tt> [protected]</tt></h3>
<p>Returns the index of the value in the database result set for the given <i>item</i> in the model.</p>
<p>The return value is identical to <i>item</i> if no columns or rows have been inserted, removed, or moved around.</p>
<p>Returns an invalid model index if <i>item</i> is out of bounds or if <i>item</i> does not point to a value in the result set.</p>
<p><b>See also </b><a href="qsqltablemodel.html#indexInQuery">QSqlTableModel::indexInQuery</a>(), <a href="qsqlquerymodel.html#insertColumns">insertColumns</a>(), and <a href="qsqlquerymodel.html#removeColumns">removeColumns</a>().</p>
<!-- @@@indexInQuery -->
<!-- $$$insertColumns[overload1]$$$insertColumnsintintconstQModelIndex& -->
<h3 class="fn"><a name="insertColumns"></a><span class="type">bool</span> QSqlQueryModel::<span class="name">insertColumns</span> ( <span class="type">int</span> <i>column</i>, <span class="type">int</span> <i>count</i>, const <span class="type"><a href="qmodelindex.html">QModelIndex</a></span> &amp; <i>parent</i> = QModelIndex() )<tt> [virtual]</tt></h3>
<p>Reimplemented from <a href="qabstractitemmodel.html#insertColumns">QAbstractItemModel::insertColumns</a>().</p>
<p>Inserts <i>count</i> columns into the model at position <i>column</i>. The <i>parent</i> parameter must always be an invalid <a href="qmodelindex.html">QModelIndex</a>, since the model does not support parent-child relationships.</p>
<p>Returns true if <i>column</i> 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">data</a>() and handle any inserted column separately:</p>
<pre class="cpp"> <span class="type"><a href="qvariant.html">QVariant</a></span> MyModel<span class="operator">::</span><a href="qsqlquerymodel.html#data">data</a>(<span class="keyword">const</span> <span class="type"><a href="qmodelindex.html">QModelIndex</a></span> <span class="operator">&amp;</span>item<span class="operator">,</span> <span class="type">int</span> role) <span class="keyword">const</span>
 {
     <span class="keyword">if</span> (item<span class="operator">.</span>column() <span class="operator">=</span><span class="operator">=</span> m_specialColumnNo) {
         <span class="comment">// handle column separately</span>
     }
     <span class="keyword">return</span> <span class="type"><a href="qsqlquerymodel.html">QSqlQueryModel</a></span><span class="operator">::</span>data(item<span class="operator">,</span> role);
 }</pre>
<p><b>See also </b><a href="qsqlquerymodel.html#removeColumns">removeColumns</a>().</p>
<!-- @@@insertColumns -->
<!-- $$$lastError[overload1]$$$lastError -->
<h3 class="fn"><a name="lastError"></a><span class="type"><a href="qsqlerror.html">QSqlError</a></span> QSqlQueryModel::<span class="name">lastError</span> () const</h3>
<p>Returns information about the last error that occurred on the database.</p>
<p><b>See also </b><a href="qsqlquerymodel.html#setLastError">setLastError</a>() and <a href="qsqlquerymodel.html#query">query</a>().</p>
<!-- @@@lastError -->
<!-- $$$query[overload1]$$$query -->
<h3 class="fn"><a name="query"></a><span class="type"><a href="qsqlquery.html">QSqlQuery</a></span> QSqlQueryModel::<span class="name">query</span> () const</h3>
<p>Returns the <a href="qsqlquery.html">QSqlQuery</a> associated with this model.</p>
<p><b>See also </b><a href="qsqlquerymodel.html#setQuery">setQuery</a>().</p>
<!-- @@@query -->
<!-- $$$queryChange[overload1]$$$queryChange -->
<h3 class="fn"><a name="queryChange"></a><span class="type">void</span> QSqlQueryModel::<span class="name">queryChange</span> ()<tt> [virtual protected]</tt></h3>
<p>This virtual function is called whenever the query changes. The default implementation does nothing.</p>
<p><a href="qsqlquerymodel.html#query">query</a>() returns the new query.</p>
<p><b>See also </b><a href="qsqlquerymodel.html#query">query</a>() and <a href="qsqlquerymodel.html#setQuery">setQuery</a>().</p>
<!-- @@@queryChange -->
<!-- $$$record[overload1]$$$recordint -->
<h3 class="fn"><a name="record"></a><span class="type"><a href="qsqlrecord.html">QSqlRecord</a></span> QSqlQueryModel::<span class="name">record</span> ( <span class="type">int</span> <i>row</i> ) const</h3>
<p>Returns the record containing information about the fields of the current query. If <i>row</i> 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>
<p><b>See also </b><a href="qsqlrecord.html#isEmpty">QSqlRecord::isEmpty</a>().</p>
<!-- @@@record -->
<!-- $$$record$$$record -->
<h3 class="fn"><a name="record-2"></a><span class="type"><a href="qsqlrecord.html">QSqlRecord</a></span> QSqlQueryModel::<span class="name">record</span> () const</h3>
<p>This is an overloaded function.</p>
<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>
<p><b>See also </b><a href="qsqlrecord.html#isEmpty">QSqlRecord::isEmpty</a>().</p>
<!-- @@@record -->
<!-- $$$removeColumns[overload1]$$$removeColumnsintintconstQModelIndex& -->
<h3 class="fn"><a name="removeColumns"></a><span class="type">bool</span> QSqlQueryModel::<span class="name">removeColumns</span> ( <span class="type">int</span> <i>column</i>, <span class="type">int</span> <i>count</i>, const <span class="type"><a href="qmodelindex.html">QModelIndex</a></span> &amp; <i>parent</i> = QModelIndex() )<tt> [virtual]</tt></h3>
<p>Reimplemented from <a href="qabstractitemmodel.html#removeColumns">QAbstractItemModel::removeColumns</a>().</p>
<p>Removes <i>count</i> columns from the model starting from position <i>column</i>. The <i>parent</i> parameter must always be an invalid <a href="qmodelindex.html">QModelIndex</a>, 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">QSqlQuery</a>.</p>
<p>Returns true if the columns were removed; otherwise returns false.</p>
<!-- @@@removeColumns -->
<!-- $$$rowCount[overload1]$$$rowCountconstQModelIndex& -->
<h3 class="fn"><a name="rowCount"></a><span class="type">int</span> QSqlQueryModel::<span class="name">rowCount</span> ( const <span class="type"><a href="qmodelindex.html">QModelIndex</a></span> &amp; <i>parent</i> = QModelIndex() ) const<tt> [virtual]</tt></h3>
<p>Reimplemented from <a href="qabstractitemmodel.html#rowCount">QAbstractItemModel::rowCount</a>().</p>
<p>If the database supports returning the size of a query (see <a href="qsqldriver.html#hasFeature">QSqlDriver::hasFeature</a>()), the number of rows of the current query is returned. Otherwise, returns the number of rows currently cached on the client.</p>
<p><i>parent</i> should always be an invalid <a href="qmodelindex.html">QModelIndex</a>.</p>
<p>This function was introduced in Qt 4.1.</p>
<p><b>See also </b><a href="qsqlquerymodel.html#canFetchMore">canFetchMore</a>() and <a href="qsqldriver.html#hasFeature">QSqlDriver::hasFeature</a>().</p>
<!-- @@@rowCount -->
<!-- $$$setHeaderData[overload1]$$$setHeaderDataintQt::OrientationconstQVariant&int -->
<h3 class="fn"><a name="setHeaderData"></a><span class="type">bool</span> QSqlQueryModel::<span class="name">setHeaderData</span> ( <span class="type">int</span> <i>section</i>, <span class="type"><a href="qt.html#Orientation-enum">Qt::Orientation</a></span> <i>orientation</i>, const <span class="type"><a href="qvariant.html">QVariant</a></span> &amp; <i>value</i>, <span class="type">int</span> <i>role</i> = Qt::EditRole )<tt> [virtual]</tt></h3>
<p>Reimplemented from <a href="qabstractitemmodel.html#setHeaderData">QAbstractItemModel::setHeaderData</a>().</p>
<p>Sets the caption for a horizontal header for the specified <i>role</i> to <i>value</i>. This is useful if the model is used to display data in a view (e.g&#x2e;, <a href="qtableview.html">QTableView</a>).</p>
<p>Returns true if <i>orientation</i> is <a href="qt.html#Orientation-enum">Qt::Horizontal</a> and the <i>section</i> 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>
<p><b>See also </b><a href="qsqlquerymodel.html#headerData">headerData</a>() and <a href="qsqlquerymodel.html#data">data</a>().</p>
<!-- @@@setHeaderData -->
<!-- $$$setLastError[overload1]$$$setLastErrorconstQSqlError& -->
<h3 class="fn"><a name="setLastError"></a><span class="type">void</span> QSqlQueryModel::<span class="name">setLastError</span> ( const <span class="type"><a href="qsqlerror.html">QSqlError</a></span> &amp; <i>error</i> )<tt> [protected]</tt></h3>
<p>Protected function which allows derived classes to set the value of the last error that occurred on the database to <i>error</i>.</p>
<p><b>See also </b><a href="qsqlquerymodel.html#lastError">lastError</a>().</p>
<!-- @@@setLastError -->
<!-- $$$setQuery[overload1]$$$setQueryconstQSqlQuery& -->
<h3 class="fn"><a name="setQuery"></a><span class="type">void</span> QSqlQueryModel::<span class="name">setQuery</span> ( const <span class="type"><a href="qsqlquery.html">QSqlQuery</a></span> &amp; <i>query</i> )</h3>
<p>Resets the model and sets the data provider to be the given <i>query</i>. Note that the query must be active and must not be isForwardOnly().</p>
<p><a href="qsqlquerymodel.html#lastError">lastError</a>() can be used to retrieve verbose information if there was an error setting the query.</p>
<p><b>Note:</b> Calling setQuery() will remove any inserted columns.</p>
<p><b>See also </b><a href="qsqlquerymodel.html#query">query</a>(), <a href="qsqlquery.html#isActive">QSqlQuery::isActive</a>(), <a href="qsqlquery.html#setForwardOnly">QSqlQuery::setForwardOnly</a>(), and <a href="qsqlquerymodel.html#lastError">lastError</a>().</p>
<!-- @@@setQuery -->
<!-- $$$setQuery$$$setQueryconstQString&constQSqlDatabase& -->
<h3 class="fn"><a name="setQuery-2"></a><span class="type">void</span> QSqlQueryModel::<span class="name">setQuery</span> ( const <span class="type"><a href="qstring.html">QString</a></span> &amp; <i>query</i>, const <span class="type"><a href="qsqldatabase.html">QSqlDatabase</a></span> &amp; <i>db</i> = QSqlDatabase() )</h3>
<p>This is an overloaded function.</p>
<p>Executes the query <i>query</i> for the given database connection <i>db</i>. If no database (or an invalid database) is specified, the default connection is used.</p>
<p><a href="qsqlquerymodel.html#lastError">lastError</a>() can be used to retrieve verbose information if there was an error setting the query.</p>
<p>Example:</p>
<pre class="cpp"> <span class="type"><a href="qsqlquerymodel.html">QSqlQueryModel</a></span> model;
 model<span class="operator">.</span><a href="qsqlquerymodel.html#setQuery">setQuery</a>(<span class="string">&quot;select * from MyTable&quot;</span>);
 <span class="keyword">if</span> (model<span class="operator">.</span>lastError()<span class="operator">.</span>isValid())
     <a href="qtglobal.html#qDebug">qDebug</a>() <span class="operator">&lt;</span><span class="operator">&lt;</span> model<span class="operator">.</span><a href="qsqlquerymodel.html#lastError">lastError</a>();</pre>
<p><b>See also </b><a href="qsqlquerymodel.html#query">query</a>(), <a href="qsqlquerymodel.html#queryChange">queryChange</a>(), and <a href="qsqlquerymodel.html#lastError">lastError</a>().</p>
<!-- @@@setQuery -->
</div>
      </div>
    </div>
    </div> 
    <div class="ft">
      <span></span>
    </div>
  </div> 
  <div class="footer">
    <p>
      <acronym title="Copyright">&copy;</acronym> 2015 The Qt Company Ltd.
      Documentation contributions included herein are the copyrights of
      their respective owners.</p>
    <br />
    <p>
      The documentation provided herein is licensed under the terms of the
      <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation
      License version 1.3</a> as published by the Free Software Foundation.</p>
    <p>
      Documentation sources may be obtained from <a href="http://www.qt-project.org">
      www.qt-project.org</a>.</p>
    <br />
    <p>
      Qt and respective logos are trademarks of The Qt Company Ltd 
      in Finland and/or other countries worldwide. All other trademarks are property
      of their respective owners. <a title="Privacy Policy"
      href="http://en.gitorious.org/privacy_policy/">Privacy Policy</a></p>
  </div>

  <script src="scripts/functions.js" type="text/javascript"></script>
</body>
</html>