このページでは

QException Class

QException クラスは、スレッド間で伝播可能な例外の基底クラスを提供します。詳細...

ヘッダー: #include <QException>
CMake: find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core)
qmake: QT += core
継承元:

QUnhandledException

パブリック関数

QException()
QException(const QException &other)
virtual ~QException()
virtual QException *clone() const
virtual void raise() const
QException &operator=(const QException &other)

詳細な説明

Qt Concurrent QException を継承し、以下の 2 つのヘルパー関数を実装している場合、スレッド境界を越えた例外のスローおよびキャッチをサポートします:

class MyException : public QException
{
public:
    void raise() const override { throw *this; }
    MyException *clone() const override { return new MyException(*this); }
};

QExceptionのサブクラスは、値渡しでスローされ、参照渡しでキャッチされなければなりません:

try  {
    QtConcurrent::blockingMap(list, throwFunction); // throwFunction throws MyException
} catch (MyException &e) {
    // handle exception
}

QExceptionのサブクラスではない例外をスローした場合、 Qt Concurrent 関数は、受信スレッドでQUnhandledException をスローします。

QFuture を使用する場合、以下の関数を呼び出す際に、転送された例外がスローされます:

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

[noexcept default] QException::QException()

QException オブジェクトを作成します。

[constexpr noexcept default] QException::QException(const QException &other)

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

注: この関数を使用する際は、スライシングが発生する恐れがあるため注意してください 。

clone()も参照してください 。

[virtual noexcept] QException::~QException()

このQException オブジェクトを破棄します。

[virtual] QException *QException::clone() const

QException のサブクラス内で、clone()を次のように再実装してください:

MyException *MyException::clone() const { return new MyException(*this); }

[virtual] void QException::raise() const

QException のサブクラス内で、raise()を次のように再実装してください:

void MyException::raise() const { throw *this; }

[noexcept default] QException &QException::operator=(const QException &other)

このオブジェクトに対して、other をコピー代入します。

注: この関数を使用する際は、スライシングが発生する可能性があるため注意が必要です 。

© 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.