rev*_*ers 9 c++ windows mingw exception qt4
我面临着奇怪的问题.也就是说,Qt以某种方式关闭了程序中的异常处理.我无法捕获任何异常,当我抛出异常应用程序崩溃时.
我在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;
}
Run Code Online (Sandbox Code Playgroud)
当我执行上面的程序时,我得到了这个输出:
在例外之前
此应用程序已请求Runtime以不寻常的方式终止它.
有关更多信息,请联系应用程序的支持团队.
我试图在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;
}
Run Code Online (Sandbox Code Playgroud)
输出:
异常发生之前发生异常
有谁知道为什么会这样发生以及如何解决这个问题?是否与Qt构建时使用的异常处理方法(SJLJ或Dwarf-2)类型有关?
我用旗帜重新配置并重新编译了Qt -exceptions:
D:\Qt\2010.05\qt>mingw32-make confclean && configure -exceptions && mingw32-make
现在一切正常!
谢谢大家的帮助,尤其是Nick D!
无论如何,我有没有这个标志的Qt构建是非常奇怪的.我从官方网站下载了二进制格式的Qt SDK.
| 归档时间: |
|
| 查看次数: |
4262 次 |
| 最近记录: |