我面临着奇怪的问题。也就是说,Qt 以某种方式关闭了我的程序中的异常处理。我无法捕获任何异常,当我抛出异常时,应用程序崩溃。
我在 Windows 7(64 位)上使用 Qt SDK v2010.05 中的 Qt 4.7.0(32 位)、MinGW 中的 g++ (GCC) 4.5.1、NetBeans 6.9.1。
但我也用 g++ 3.4.5(也来自 MinGW)和 Qt Creator 2.0.1 对此进行了检查 - 同样奇怪的行为。
例如(最简单的情况):
#include <Qt/QApplication.h>
#include <iostream>
#include <stdexcept>
#include <cstdlib>
using namespace std;
int main(int argc, char* argv[]) {
QApplication app(argc, argv);
try {
cout << "Before exception" << endl;
throw runtime_error("Exception occured");
cout << "After exception" << endl;
} catch (runtime_error& exc) {
cout << exc.what() << endl;
exit(1);
}
return 0;
}
当我执行上面的程序时,我得到以下输出:
异常前
此应用程序已请求运行时以异常方式终止它。
请联系应用程序的支持团队以获取更多信息。
我尝试向 g++ 添加标志“-fexceptions”,但它没有改变任何东西。
当我不使用 Qt 时,一切正常:
#include <Qt/QApplication.h> // It is not caused only by including Qt header
// so it doesn't matter if I comment this out or not
#include <iostream>
#include <stdexcept>
#include <cstdlib>
using namespace std;
int main(int argc, char* argv[]) {
// QApplication app(argc, argv);
try {
cout << "Before exception" << endl;
throw runtime_error("Exception occured");
cout << "After exception" << endl;
} catch (runtime_error& exc) {
cout << exc.what() << endl;
exit(1);
}
return 0;
}
输出:
异常前
发生异常
有谁知道为什么会这样以及如何解决这个问题?这与构建 Qt 时使用的异常处理方法(SJLJ 或 Dwarf-2)的类型有关吗?
我已经用 flag 重新配置并重新编译了 Qt-exceptions
:
D:\Qt\2010.05\qt>mingw32-make confclean && configure -exceptions && mingw32-make
现在一切都好了!
感谢大家的帮助,特别是 Nick D!
不管怎样,我在没有这个标志的情况下构建了 Qt,这很奇怪。我从官方网站下载了二进制形式的 Qt SDK。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)