我面临奇怪的问题。 也就是说,Qt以某种方式closures了我的程序中的exception处理。 我无法捕捉任何exception,而当我抛出一个exception应用程序崩溃。
我在Windows 7(64位)上使用Qt SDK v2010.05的Qt 4.7.0(32位),MinGW的NetBeans 6.9.1的g ++(GCC)4.5.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; }
输出:
在例外之前
发生exception
有人知道为什么会发生这种情况,以及如何解决这个问题? 是否与Qt构build时使用的exception处理方法(SJLJ或Dwarf-2)有关?
我已经重新编译并重新编译了Qt,并标记为:
D:\Qt\2010.05\qt>mingw32-make confclean && configure -exceptions && mingw32-make
现在一切都好!
感谢所有的帮助,特别是尼克D!
无论如何,奇怪的是我没有这个标志的Qt构建。 我从官方网站下载了二进制形式的Qt SDK。