このページでは

QSqlError Class

QSqlError クラスは、SQL データベースのエラー情報を提供します。詳細...

ヘッダー: #include <QSqlError>
CMake: find_package(Qt6 REQUIRED COMPONENTS Sql)
target_link_libraries(mytarget PRIVATE Qt6::Sql)
qmake: QT += sql

パブリック型

enum ErrorType { NoError, ConnectionError, StatementError, TransactionError, UnknownError }

パブリック関数

QSqlError(const QString &driverText = QString(), const QString &databaseText = QString(), QSqlError::ErrorType type = NoError, const QString &nativeErrorCode = QString())
QSqlError(const QSqlError &other)
QSqlError(QSqlError &&other)
~QSqlError()
QString databaseText() const
QString driverText() const
bool isValid() const
QString nativeErrorCode() const
void swap(QSqlError &other)
QString text() const
QSqlError::ErrorType type() const
bool operator!=(const QSqlError &other) const
QSqlError &operator=(QSqlError &&other)
QSqlError &operator=(const QSqlError &other)
bool operator==(const QSqlError &other) const

詳細な説明

QSqlError オブジェクトは、driverText() およびdatabaseText() のメッセージ(あるいは、これらを連結したtext())、ならびにnativeErrorCode() およびtype() を含む、データベース固有のエラーデータを提供することができます。

QSqlDatabase::lastError() およびQSqlQuery::lastError()も参照してください 。

メンバ型のドキュメント

enum QSqlError::ErrorType

この列挙型は、エラーが発生したコンテキスト(接続エラー、ステートメントエラーなど)を表します。

定数値説明
QSqlError::NoError0エラーは発生しませんでした。
QSqlError::ConnectionError1接続エラー。
QSqlError::StatementError2SQL ステートメントの構文エラー。
QSqlError::TransactionError3トランザクションの失敗エラー。
QSqlError::UnknownError4不明なエラー。

メンバー関数のドキュメント

QSqlError::QSqlError(const QString &driverText = QString(), const QString &databaseText = QString(), QSqlError::ErrorType type = NoError, const QString &nativeErrorCode = QString())

ドライバのエラーメッセージ「driverText 」、データベース固有のエラーメッセージ「databaseText 」、型「type 」、およびネイティブエラーコード「nativeErrorCode 」を含むエラーオブジェクトを生成します。

QSqlError::QSqlError(const QSqlError &other)

other のコピーを作成します。

[constexpr noexcept default] QSqlError::QSqlError(QSqlError &&other)

QSqlErrorインスタンスをムーブコンストラクタで生成し、other が指していたのと同じオブジェクトを指すようにします。

注: 移動元のオブジェクト other は 、破棄と新しい値の代入のみが有効な操作となる、部分的に形成された状態になります。

[noexcept] QSqlError::~QSqlError()

オブジェクトを破棄し、割り当てられていたリソースをすべて解放します。

QString QSqlError::databaseText() const

データベースから報告されたエラーのテキストを返します。これにはデータベース固有の説明が含まれている場合があり、空の場合もあります。

driverText() およびtext()も参照してください 。

QString QSqlError::driverText() const

ドライバから報告されたエラーのテキストを返します。これには、データベース固有の説明が含まれている場合があります。また、空の場合もあります。

databaseText() およびtext()も参照してください 。

bool QSqlError::isValid() const

エラーが設定されている場合は `true ` を返し、そうでない場合は `false` を返します。

例:

QSqlQueryModel model;
model.setQuery("select * from myTable");
if(model.lastError().isValid())
    qDebug() << model.lastError();

「type()」も参照してください 。

QString QSqlError::nativeErrorCode() const

データベース固有(ネイティブ)のエラーコードを返します。特定できない場合は空の文字列を返します。

注:一部の ドライバ(DB2やODBCなど)では、複数のエラーコードが返される場合があります。その場合、エラーコード間の区切り文字として; が使用されます。

[noexcept] void QSqlError::swap(QSqlError &other)

このエラーを `other` に置き換えます。この操作は非常に高速で、失敗することはありません。

QString QSqlError::text() const

これは、databaseText() とdriverText() を結合して単一の文字列として返す便利関数です。

driverText() およびdatabaseText()も参照してください 。

QSqlError::ErrorType QSqlError::type() const

エラーの型を返します。型を特定できない場合は -1 を返します。

bool QSqlError::operator!=(const QSqlError &other) const

other エラーのtype()およびnativeErrorCode()を、このエラーと比較し、等しくない場合はtrue を返します。

[noexcept] QSqlError &QSqlError::operator=(QSqlError &&other)

other をこのQSqlError インスタンスに割り当てます。

注: 移動元のオブジェクト other は 、部分的に形成された状態となり、この状態では破棄と新しい値への代入のみが有効な操作となります。

QSqlError &QSqlError::operator=(const QSqlError &other)

other エラーの値を、このエラーに割り当てます。

bool QSqlError::operator==(const QSqlError &other) const

other エラーのtype()およびnativeErrorCode()を、このエラーと比較し、一致する場合はtrue を返します。

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. 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.