我做了一个QException的子类,如下所示:
#include <QtConcurrent>
#include <QException>
class ProcessingException : public QException
{
public:
ProcessingException(QString const& message) :
message(message)
{}
virtual ~ProcessingException()
{
}
void raise() const { throw *this; }
ProcessingException *clone() const { return new ProcessingException(*this); }
QString getMessage() const
{
return message;
}
private:
QString message;
};
从QtConcurrent :: run运行的方法中,我用throw new ProcessingException("test");抛出该子类的实例。然后,如果我正确理解了文档,则当我使用.waitForFinished()收集将来的结果时,Qt应该重新抛出QException子类。但是,使用这种方法,我只能捕获QUnhandledException:
try
{
watcher->waitForFinished();
}
catch(const ProcessingException &e)
{
qCritical() << "Caught:" << e.getMessage();
}
catch(const QUnhandledException &e)
{
qCritical() <<

最低0.47元/天 解锁文章
5815

被折叠的 条评论
为什么被折叠?



