如果您在Google上搜索“ QCoreApplicationPrivate::sendPostedEvents exception”,则会发现大量点击,这至少部分是因为此方法吞噬了事件处理程序(例如paint事件处理程序等)中抛出的异常。因此,程序员不知道在哪里抛出异常,并且很难找到错误。我正在寻找解决方法,以解决程序员又遇到的另一种Qt
痛苦。这是qcoreapplication.cpp
的实际代码片段:
#ifdef QT_NO_EXCEPTIONS
QCoreApplication::sendEvent(r, e);
#else
try {
QCoreApplication::sendEvent(r, e);
} catch (...) {
delete e;
locker.relock();
// since we were interrupted, we need another pass to make sure we clean everything up
data->canWait = false;
// uglehack: copied from below
--data->postEventList.recursion;
if (!data->postEventList.recursion && !data->canWait && data->eventDispatcher)
data->eventDispatcher->wakeUp();
throw; // rethrow
}
#endif
Qt
天才之路!在我的代码的深处,抛出了一个异常,但是由于这个宝石,我不知道在哪里。解决该问题的一种方法在上面的代码中显示:禁用异常支持并重新编译Qt
,或更改代码并重新编译。即使可能不可能:在任何操作系统下是否都存在针对此问题的其他解决方法?编辑:我正在使用
Qt4.8
。 最佳答案
在Qt 5中,您要做的就是重新实现QCoreApplication::notify
并在Qt之前捕获异常。而已。参见,例如,this answer。
在Qt 4中,您需要从Qt 5向后移植代码。
关于c++ - Qts古老的QCoreApplicationPrivate::sendPostedEvents异常吃,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23359692/