我正面临着奇怪的问题。也就是说,Qt以某种方式关闭了我的程序中的异常处理。我无法捕获任何异常,并且当我抛出一个异常应用程序崩溃时。
我在Windows 7 (64位)上使用QTSDKv2010.05中的QT4.7.0 (32位),在MinGW上使用QT4.7.0(32位) 4.5.1,在MinGW上使用NetBeans 6.9.1。但是我也用g++ 3.4.5 (也来自MinGW)和QtCreator2.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++中添加标志“g++”,但是它没有改变任何事情。
当我不使用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)的类型有关?
发布于 2010-11-11 02:27:07
我已经用标志-exceptions重新配置和重新编译了Qt
D:\Qt\2010.05\qt>mingw32-make confclean && configure -exceptions && mingw32-make
现在一切都好了!
感谢大家的帮助,尤其是尼克D!
不管怎么说,很奇怪的是,我有Qt构建没有这个标志。我从官方网站下载了二进制格式的Qt。
发布于 2020-12-12 12:25:38
不再需要在Qt中使用-exceptions标志。在exception 4中,这是默认的,我的Windows应用程序愉快地使用了范围广泛的异常处理,没有任何问题。Qt生成使用/EHsc编译器选项,它打开了正常的异常处理。
https://stackoverflow.com/questions/4149118
复制相似问题