<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <!-- qsqlerror.cpp --> <title>QSqlError Class | Qt SQL 5.11</title> <link rel="stylesheet" type="text/css" href="style/offline-simple.css" /> <script type="text/javascript"> document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css"); // loading style sheet breaks anchors that were jumped to before // so force jumping to anchor again setTimeout(function() { var anchor = location.hash; // need to jump to different anchor first (e.g. none) location.hash = "#"; setTimeout(function() { location.hash = anchor; }, 0); }, 0); </script> </head> <body> <div class="header" id="qtdocheader"> <div class="main"> <div class="main-rounded"> <div class="navigationbar"> <table><tr> <td ><a href="../qtdoc/index.html">Qt 5.11</a></td><td ><a href="qtsql-index.html">Qt SQL</a></td><td ><a href="qtsql-module.html">C++ Classes</a></td><td >QSqlError</td></tr></table><table class="buildversion"><tr> <td id="buildversion" width="100%" align="right">Qt 5.11.2 Reference Documentation</td> </tr></table> </div> </div> <div class="content"> <div class="line"> <div class="content mainContent"> <div class="sidebar"> <div class="toc"> <h3><a name="toc">Contents</a></h3> <ul> <li class="level1"><a href="#public-types">Public Types</a></li> <li class="level1"><a href="#public-functions">Public Functions</a></li> <li class="level1"><a href="#details">Detailed Description</a></li> </ul> </div> <div class="sidebar-content" id="sidebar-content"></div></div> <h1 class="title">QSqlError Class</h1> <!-- $$$QSqlError-brief --> <p>The <a href="qsqlerror.html">QSqlError</a> class provides SQL database error information. <a href="#details">More...</a></p> <!-- @@@QSqlError --> <div class="table"><table class="alignedsummary"> <tr><td class="memItemLeft rightAlign topAlign"> Header:</td><td class="memItemRight bottomAlign"> <span class="preprocessor">#include <QSqlError></span> </td></tr><tr><td class="memItemLeft rightAlign topAlign"> qmake:</td><td class="memItemRight bottomAlign"> QT += sql</td></tr></table></div><ul> <li><a href="qsqlerror-members.html">List of all members, including inherited members</a></li> <li><a href="qsqlerror-obsolete.html">Obsolete members</a></li> </ul> <a name="public-types"></a> <h2 id="public-types">Public Types</h2> <div class="table"><table class="alignedsummary"> <tr><td class="memItemLeft rightAlign topAlign"> enum </td><td class="memItemRight bottomAlign"><b><a href="qsqlerror.html#ErrorType-enum">ErrorType</a></b> { NoError, ConnectionError, StatementError, TransactionError, UnknownError }</td></tr> </table></div> <a name="public-functions"></a> <h2 id="public-functions">Public Functions</h2> <div class="table"><table class="alignedsummary"> <tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qsqlerror.html#QSqlError">QSqlError</a></b>(const QString &<i>driverText</i> = QString(), const QString &<i>databaseText</i> = QString(), QSqlError::ErrorType <i>type</i> = NoError, const QString &<i>code</i> = QString())</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qsqlerror.html#QSqlError-2">QSqlError</a></b>(const QSqlError &<i>other</i>)</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qsqlerror.html#QSqlError-3">QSqlError</a></b>(QSqlError &&<i>other</i>)</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qsqlerror.html#dtor.QSqlError">~QSqlError</a></b>()</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> QString </td><td class="memItemRight bottomAlign"><b><a href="qsqlerror.html#databaseText">databaseText</a></b>() const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> QString </td><td class="memItemRight bottomAlign"><b><a href="qsqlerror.html#driverText">driverText</a></b>() const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qsqlerror.html#isValid">isValid</a></b>() const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> QString </td><td class="memItemRight bottomAlign"><b><a href="qsqlerror.html#nativeErrorCode">nativeErrorCode</a></b>() const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qsqlerror.html#swap">swap</a></b>(QSqlError &<i>other</i>)</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> QString </td><td class="memItemRight bottomAlign"><b><a href="qsqlerror.html#text">text</a></b>() const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> QSqlError::ErrorType </td><td class="memItemRight bottomAlign"><b><a href="qsqlerror.html#type">type</a></b>() const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qsqlerror.html#operator-not-eq">operator!=</a></b>(const QSqlError &<i>other</i>) const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> QSqlError &</td><td class="memItemRight bottomAlign"><b><a href="qsqlerror.html#operator-eq">operator=</a></b>(const QSqlError &<i>other</i>)</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> QSqlError &</td><td class="memItemRight bottomAlign"><b><a href="qsqlerror.html#operator-eq-1">operator=</a></b>(QSqlError &&<i>other</i>)</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qsqlerror.html#operator-eq-eq">operator==</a></b>(const QSqlError &<i>other</i>) const</td></tr> </table></div> <a name="details"></a> <!-- $$$QSqlError-description --> <div class="descr"> <h2 id="details">Detailed Description</h2> <p>The <a href="qsqlerror.html">QSqlError</a> class provides SQL database error information.</p> <p>A <a href="qsqlerror.html">QSqlError</a> object can provide database-specific error data, including the <a href="qsqlerror.html#driverText">driverText</a>() and <a href="qsqlerror.html#databaseText">databaseText</a>() messages (or both concatenated together as <a href="qsqlerror.html#text">text</a>()), and the <a href="qsqlerror.html#nativeErrorCode">nativeErrorCode</a>() and <a href="qsqlerror.html#type">type</a>().</p> </div> <p><b>See also </b><a href="qsqldatabase.html#lastError">QSqlDatabase::lastError</a>() and <a href="qsqlquery.html#lastError">QSqlQuery::lastError</a>().</p> <!-- @@@QSqlError --> <div class="types"> <h2>Member Type Documentation</h2> <!-- $$$ErrorType$$$NoError$$$ConnectionError$$$StatementError$$$TransactionError$$$UnknownError --> <h3 class="fn" id="ErrorType-enum"><a name="ErrorType-enum"></a>enum QSqlError::<span class="name">ErrorType</span></h3> <p>This enum type describes the context in which the error occurred, e.g., a connection error, a statement error, etc.</p> <div class="table"><table class="valuelist"><tr valign="top" class="odd"><th class="tblConst">Constant</th><th class="tblval">Value</th><th class="tbldscr">Description</th></tr> <tr><td class="topAlign"><code>QSqlError::NoError</code></td><td class="topAlign tblval"><code>0</code></td><td class="topAlign">No error occurred.</td></tr> <tr><td class="topAlign"><code>QSqlError::ConnectionError</code></td><td class="topAlign tblval"><code>1</code></td><td class="topAlign">Connection error.</td></tr> <tr><td class="topAlign"><code>QSqlError::StatementError</code></td><td class="topAlign tblval"><code>2</code></td><td class="topAlign">SQL statement syntax error.</td></tr> <tr><td class="topAlign"><code>QSqlError::TransactionError</code></td><td class="topAlign tblval"><code>3</code></td><td class="topAlign">Transaction failed error.</td></tr> <tr><td class="topAlign"><code>QSqlError::UnknownError</code></td><td class="topAlign tblval"><code>4</code></td><td class="topAlign">Unknown error.</td></tr> </table></div> <!-- @@@ErrorType --> </div> <div class="func"> <h2>Member Function Documentation</h2> <!-- $$$QSqlError[overload1]$$$QSqlErrorconstQString&constQString&QSqlError::ErrorTypeconstQString& --> <h3 class="fn" id="QSqlError"><a name="QSqlError"></a>QSqlError::<span class="name">QSqlError</span>(const <span class="type"><a href="../qtcore/qstring.html">QString</a></span> &<i>driverText</i> = QString(), const <span class="type"><a href="../qtcore/qstring.html">QString</a></span> &<i>databaseText</i> = QString(), <span class="type"><a href="qsqlerror.html#ErrorType-enum">QSqlError::ErrorType</a></span> <i>type</i> = NoError, const <span class="type"><a href="../qtcore/qstring.html">QString</a></span> &<i>code</i> = QString())</h3> <p>Constructs an error containing the driver error text <i>driverText</i>, the database-specific error text <i>databaseText</i>, the type <i>type</i> and the error code <i>code</i>.</p> <p><b>Note: </b>DB2: It is possible for DB2 to report more than one error code. When this happens, <code>;</code> is used as separator between the error codes.</p><!-- @@@QSqlError --> <!-- $$$QSqlError$$$QSqlErrorconstQSqlError& --> <h3 class="fn" id="QSqlError-2"><a name="QSqlError-2"></a>QSqlError::<span class="name">QSqlError</span>(const <span class="type"><a href="qsqlerror.html#QSqlError">QSqlError</a></span> &<i>other</i>)</h3> <p>Creates a copy of <i>other</i>.</p> <!-- @@@QSqlError --> <!-- $$$QSqlError$$$QSqlErrorQSqlError&& --> <h3 class="fn" id="QSqlError-3"><a name="QSqlError-3"></a>QSqlError::<span class="name">QSqlError</span>(<span class="type"><a href="qsqlerror.html#QSqlError">QSqlError</a></span> &&<i>other</i>)</h3> <p>Move-constructs a <a href="qsqlerror.html">QSqlError</a> instance, making it point at the same object that <i>other</i> was pointing to.</p> <p><b>Note: </b>The moved-from object <i>other</i> is placed in a partially-formed state, in which the only valid operations are destruction and assignment of a new value.</p><p>This function was introduced in Qt 5.10.</p> <!-- @@@QSqlError --> <!-- $$$~QSqlError[overload1]$$$~QSqlError --> <h3 class="fn" id="dtor.QSqlError"><a name="dtor.QSqlError"></a>QSqlError::<span class="name">~QSqlError</span>()</h3> <p>Destroys the object and frees any allocated resources.</p> <!-- @@@~QSqlError --> <!-- $$$databaseText[overload1]$$$databaseText --> <h3 class="fn" id="databaseText"><a name="databaseText"></a><span class="type"><a href="../qtcore/qstring.html">QString</a></span> QSqlError::<span class="name">databaseText</span>() const</h3> <p>Returns the text of the error as reported by the database. This may contain database-specific descriptions; it may be empty.</p> <p><b>See also </b><a href="qsqlerror-obsolete.html#setDatabaseText">setDatabaseText</a>(), <a href="qsqlerror.html#driverText">driverText</a>(), and <a href="qsqlerror.html#text">text</a>().</p> <!-- @@@databaseText --> <!-- $$$driverText[overload1]$$$driverText --> <h3 class="fn" id="driverText"><a name="driverText"></a><span class="type"><a href="../qtcore/qstring.html">QString</a></span> QSqlError::<span class="name">driverText</span>() const</h3> <p>Returns the text of the error as reported by the driver. This may contain database-specific descriptions. It may also be empty.</p> <p><b>See also </b><a href="qsqlerror-obsolete.html#setDriverText">setDriverText</a>(), <a href="qsqlerror.html#databaseText">databaseText</a>(), and <a href="qsqlerror.html#text">text</a>().</p> <!-- @@@driverText --> <!-- $$$isValid[overload1]$$$isValid --> <h3 class="fn" id="isValid"><a name="isValid"></a><span class="type">bool</span> QSqlError::<span class="name">isValid</span>() const</h3> <p>Returns <code>true</code> if an error is set, otherwise false.</p> <p>Example:</p> <pre class="cpp"> <span class="type"><a href="qsqlquerymodel.html">QSqlQueryModel</a></span> model; model<span class="operator">.</span>setQuery(<span class="string">"select * from myTable"</span>); <span class="keyword">if</span> (model<span class="operator">.</span>lastError()<span class="operator">.</span>isValid()) <a href="../qtcore/qtglobal.html#qDebug">qDebug</a>() <span class="operator"><</span><span class="operator"><</span> model<span class="operator">.</span>lastError(); </pre> <p><b>See also </b><a href="qsqlerror.html#type">type</a>().</p> <!-- @@@isValid --> <!-- $$$nativeErrorCode[overload1]$$$nativeErrorCode --> <h3 class="fn" id="nativeErrorCode"><a name="nativeErrorCode"></a><span class="type"><a href="../qtcore/qstring.html">QString</a></span> QSqlError::<span class="name">nativeErrorCode</span>() const</h3> <p>Returns the database-specific error code, or an empty string if it cannot be determined.</p> <!-- @@@nativeErrorCode --> <!-- $$$swap[overload1]$$$swapQSqlError& --> <h3 class="fn" id="swap"><a name="swap"></a><span class="type">void</span> QSqlError::<span class="name">swap</span>(<span class="type"><a href="qsqlerror.html#QSqlError">QSqlError</a></span> &<i>other</i>)</h3> <p>Swaps error <i>other</i> with this error. This operation is very fast and never fails.</p> <p>This function was introduced in Qt 5.10.</p> <!-- @@@swap --> <!-- $$$text[overload1]$$$text --> <h3 class="fn" id="text"><a name="text"></a><span class="type"><a href="../qtcore/qstring.html">QString</a></span> QSqlError::<span class="name">text</span>() const</h3> <p>This is a convenience function that returns <a href="qsqlerror.html#databaseText">databaseText</a>() and <a href="qsqlerror.html#driverText">driverText</a>() concatenated into a single string.</p> <p><b>See also </b><a href="qsqlerror.html#driverText">driverText</a>() and <a href="qsqlerror.html#databaseText">databaseText</a>().</p> <!-- @@@text --> <!-- $$$type[overload1]$$$type --> <h3 class="fn" id="type"><a name="type"></a><span class="type"><a href="qsqlerror.html#ErrorType-enum">QSqlError::ErrorType</a></span> QSqlError::<span class="name">type</span>() const</h3> <p>Returns the error type, or -1 if the type cannot be determined.</p> <p><b>See also </b><a href="qsqlerror-obsolete.html#setType">setType</a>().</p> <!-- @@@type --> <!-- $$$operator!=[overload1]$$$operator!=constQSqlError& --> <h3 class="fn" id="operator-not-eq"><a name="operator-not-eq"></a><span class="type">bool</span> QSqlError::<span class="name">operator!=</span>(const <span class="type"><a href="qsqlerror.html#QSqlError">QSqlError</a></span> &<i>other</i>) const</h3> <p>Compare the <i>other</i> error's values to this error and returns <code>true</code> if it is not equal.</p> <!-- @@@operator!= --> <!-- $$$operator=[overload1]$$$operator=constQSqlError& --> <h3 class="fn" id="operator-eq"><a name="operator-eq"></a><span class="type"><a href="qsqlerror.html#QSqlError">QSqlError</a></span> &QSqlError::<span class="name">operator=</span>(const <span class="type"><a href="qsqlerror.html#QSqlError">QSqlError</a></span> &<i>other</i>)</h3> <p>Assigns the <i>other</i> error's values to this error.</p> <!-- @@@operator= --> <!-- $$$operator=$$$operator=QSqlError&& --> <h3 class="fn" id="operator-eq-1"><a name="operator-eq-1"></a><span class="type"><a href="qsqlerror.html#QSqlError">QSqlError</a></span> &QSqlError::<span class="name">operator=</span>(<span class="type"><a href="qsqlerror.html#QSqlError">QSqlError</a></span> &&<i>other</i>)</h3> <p>Move-assigns <i>other</i> to this <a href="qsqlerror.html">QSqlError</a> instance.</p> <p><b>Note: </b>The moved-from object <i>other</i> is placed in a partially-formed state, in which the only valid operations are destruction and assignment of a new value.</p><p>This function was introduced in Qt 5.10.</p> <!-- @@@operator= --> <!-- $$$operator==[overload1]$$$operator==constQSqlError& --> <h3 class="fn" id="operator-eq-eq"><a name="operator-eq-eq"></a><span class="type">bool</span> QSqlError::<span class="name">operator==</span>(const <span class="type"><a href="qsqlerror.html#QSqlError">QSqlError</a></span> &<i>other</i>) const</h3> <p>Compare the <i>other</i> error's values to this error and returns <code>true</code>, if it equal.</p> <!-- @@@operator== --> </div> </div> </div> </div> </div> </div> <div class="footer"> <p> <acronym title="Copyright">©</acronym> 2018 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners.<br/> 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.<br/> 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. </p> </div> </body> </html>