En esta página

QException Class

La clase QException proporciona una clase base para excepciones que pueden ser transferidas a través de hilos. Más...

Cabecera: #include <QException>
CMake: find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core)
qmake: QT += core
Heredado Por:

QUnhandledException

Funciones Públicas

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

Descripción detallada

Qt Concurrent soporta lanzar y capturar excepciones a través de los límites de los hilos, siempre que la excepción herede de QException e implemente dos funciones de ayuda:

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

Las subclases de QException deben lanzarse por valor y capturarse por referencia:

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

Si lanza una excepción que no es una subclase de QException, las funciones Qt Concurrent lanzarán un QUnhandledException en el hilo receptor.

Cuando se utiliza QFuture, se lanzarán excepciones transferidas al llamar a las siguientes funciones:

Documentación de las funciones miembro

[noexcept] QException::QException()

Construye un objeto QException.

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

Crea una copia de other.

Nota: Tenga cuidado al utilizar esta función, ya que corre el riesgo de rebanar.

Véase también clone().

[virtual noexcept] QException::~QException()

Destruye este objeto QException.

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

En su subclase QException, reimplemente clone() de la siguiente manera:

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

[virtual] void QException::raise() const

En su subclase QException, reimplemente raise() de la siguiente manera:

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

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

Copia-asigna other sobre este objeto.

Nota: Tenga cuidado al utilizar esta función, ya que corre el riesgo de rebanar.

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