QException Class
Die Klasse QException bietet eine Basisklasse für Ausnahmen, die über Threads hinweg übertragen werden können. Mehr...
Kopfzeile: | #include <QException> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS Core) target_link_libraries(mytarget PRIVATE Qt6::Core) |
qmake: | QT += core |
Vererbt von: |
Öffentliche Funktionen
QException() | |
QException(const QException &other) | |
virtual | ~QException() |
virtual QException * | clone() const |
virtual void | raise() const |
QException & | operator=(const QException &other) |
Detaillierte Beschreibung
Qt Concurrent unterstützt das Auslösen und Abfangen von Exceptions über Thread-Grenzen hinweg, vorausgesetzt, die Exception 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); } };
QException-Unterklassen müssen per Wert ausgelöst und per Referenz abgefangen werden:
try { QtConcurrent::blockingMap(list, throwFunction); // throwFunction throws MyException } catch (MyException &e) { // handle exception }
Wenn Sie eine Ausnahme auslösen, die nicht eine Unterklasse von QException ist, werden die Qt Concurrent Funktionen eine QUnhandledException im Empfänger-Thread auslösen.
Bei Verwendung von QFuture werden übertragene Ausnahmen beim Aufruf der folgenden Funktionen ausgelöst:
Dokumentation der Mitgliedsfunktionen
[noexcept]
QException::QException()
Konstruiert ein QException-Objekt.
[constexpr noexcept]
QException::QException(const QException &other)
Erzeugt eine Kopie von other.
Hinweis: Seien Sie vorsichtig, wenn Sie diese Funktion verwenden, da die Gefahr besteht, dass Sie die Kopie zerschneiden.
Siehe auch clone().
[virtual noexcept]
QException::~QException()
Zerstört dieses QException Objekt.
[virtual]
QException *QException::clone() const
Implementieren Sie clone() in Ihrer Unterklasse QException wie folgt neu:
MyException *MyException::clone() const { return new MyException(*this); }
[virtual]
void QException::raise() const
Implementieren Sie raise() in Ihrer Unterklasse QException wie folgt neu:
void MyException::raise() const { throw *this; }
[noexcept]
QException &QException::operator=(const QException &other)
Kopieren - überträgt other auf dieses Objekt.
Hinweis: Seien Sie vorsichtig, wenn Sie diese Funktion verwenden, da die Gefahr besteht, dass Sie das Objekt zerschneiden.
© 2025 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.