QException Class
A classe QException fornece uma classe base para exceções que podem ser transferidas entre threads. Mais...
| Cabeçalho: | #include <QException> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Core) target_link_libraries(mytarget PRIVATE Qt6::Core) |
| qmake: | QT += core |
| Herdado por: |
Funções públicas
| QException() | |
| QException(const QException &other) | |
| virtual | ~QException() |
| virtual QException * | clone() const |
| virtual void | raise() const |
| QException & | operator=(const QException &other) |
Descrição detalhada
Qt Concurrent suporta o lançamento e a captura de exceções entre threads, desde que a exceção herde de QException e implemente duas funções auxiliares:
class MyException : public QException
{
public:
void raise() const override { throw *this; }
MyException *clone() const override { return new MyException(*this); }
};As subclasses de QException devem ser lançadas por valor e capturadas por referência:
try {
QtConcurrent::blockingMap(list, throwFunction); // throwFunction throws MyException
} catch (MyException &e) {
// handle exception
}Se você lançar uma exceção que não seja uma subclasse de QException, as Qt Concurrent funções lançarão uma exceção ` QUnhandledException ` na thread receptora.
Ao usar ` QFuture`, as exceções transferidas serão lançadas ao chamar as seguintes funções:
Documentação das funções de membro
[noexcept default] QException::QException()
Cria um objeto QException.
[constexpr noexcept default] QException::QException(const QException &other)
Cria uma cópia de other.
Observação: tenha cuidado ao usar esta função, pois há risco de ocorrer “slicing”.
Veja também clone().
[virtual noexcept] QException::~QException()
Destrói este objeto ` QException `.
[virtual] QException *QException::clone() const
Na sua subclasse ` QException `, reimplemente o método `clone()` da seguinte maneira:
MyException *MyException::clone() const { return new MyException(*this); }[virtual] void QException::raise() const
Na sua subclasse ` QException `, reimplemente o método `raise()` da seguinte forma:
void MyException::raise() const { throw *this; }[noexcept default] QException &QException::operator=(const QException &other)
Atribui por cópia o ` other ` a este objeto.
Observação: tenha cuidado ao usar esta função, pois há risco de ocorrer um “slicing”.
© 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.