Auf dieser Seite

QException Class

Die Klasse „QException“ dient als Basisklasse für Ausnahmen, die zwischen Threads übertragen werden können. Mehr...

Header: #include <QException>
CMake: find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core)
qmake: QT += core
Vererbt an:

QUnhandledException

Öffentliche Funktionen

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

Ausführliche Beschreibung

Qt Concurrent unterstützt das Auslösen und Abfangen von Ausnahmen über Thread-Grenzen hinweg, vorausgesetzt, die Ausnahme erbt von QException und implementiert zwei Hilfsfunktionen:

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

Unterklassen von QException müssen als Wert ausgelöst und als Referenz abgefangen werden:

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

Wenn Sie eine Ausnahme auslösen, die keine Unterklasse von QException ist, lösen die Qt Concurrent Funktionen im Empfänger-Thread eine „ QUnhandledException “ auslösen.

Bei Verwendung von ` QFuture` werden übertragene Ausnahmen beim Aufruf der folgenden Funktionen ausgelöst:

Dokumentation zu Mitgliedsfunktionen

[noexcept default] QException::QException()

Erstellt ein QException-Objekt.

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

Erstellt eine Kopie von „ other “.

Hinweis: Seien Sie bei der Verwendung dieser Funktion vorsichtig, da die Gefahr eines Slicing besteht.

Siehe auch clone().

[virtual noexcept] QException::~QException()

Löscht dieses „ QException “-Objekt.

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

Implementieren Sie in Ihrer Unterklasse „ QException “ die Methode „clone()“ wie folgt neu:

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

[virtual] void QException::raise() const

Implementieren Sie in Ihrer Unterklasse „ QException “ die Methode „raise()“ wie folgt neu:

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

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

Weist diesem Objekt „ other “ per Kopieren zu.

Hinweis: Seien Sie bei der Verwendung dieser Funktion vorsichtig, da die Gefahr eines Slicing besteht.

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