QMessageBox中的initializeGL再次调用initializeGL
void MyGlWidget::initializeGL() {
try {
throw std::exception();
} catch(...) {
QMessageBox::critical(this, tr("Exception"),
tr("Exception occured"));
}
}
在 catch() 中显示消息框,执行再次进入initializeGL(),并显示第二个消息框,
我试图通过布尔变量来避免这种情况:
void MyGlWidget::initializeGL() {
if(in_initializeGL_)
return;
in_initializeGL_ = true;
try {
throw std::exception();
} catch(...) {
QMessageBox::critical(this, tr("Exception"),
tr("Exception occured"));
}
in_initializeGL_ = false;
}
但这会导致崩溃。所以我决定在paintGL()中显示错误(它还显示2个消息框):
void MyGlWidget::paintGL() {
if(in_paintGL_)
return;
in_paintGL_ = true;
if (!exception_msg_.isEmpty()) {
QMessageBox::critical(this, tr("Exception"),
exception_msg_);
exception_msg_.clear();
}
// rendering stuff
in_paintGL_ = false;
}
void MyGlWidget::initializeGL() {
try {
throw std::exception();
} catch(...) {
exception_msg_ = "Exception in initializeGL()";
}
}
这解决了问题,但代码很难看。这个问题有更好的解决方案吗?
Qt4.7 VS2008
void MyGlWidget::initializeGL() {
try {
throw std::exception();
} catch(...) {
QMessageBox::critical(this, tr("Exception"),
tr("Exception occured"));
}
}
in catch() messagebox is shown and execution goes into initializeGL() again, and shows a second message box
I'm trying to avoid this via a bool variable:
void MyGlWidget::initializeGL() {
if(in_initializeGL_)
return;
in_initializeGL_ = true;
try {
throw std::exception();
} catch(...) {
QMessageBox::critical(this, tr("Exception"),
tr("Exception occured"));
}
in_initializeGL_ = false;
}
But this leads to crash. So I decided to show error in paintGL()(it also shows 2 messageboxes):
void MyGlWidget::paintGL() {
if(in_paintGL_)
return;
in_paintGL_ = true;
if (!exception_msg_.isEmpty()) {
QMessageBox::critical(this, tr("Exception"),
exception_msg_);
exception_msg_.clear();
}
// rendering stuff
in_paintGL_ = false;
}
void MyGlWidget::initializeGL() {
try {
throw std::exception();
} catch(...) {
exception_msg_ = "Exception in initializeGL()";
}
}
This solves the problem but the code ugly. Is there a more nice solution of this problem?
Qt4.7 VS2008
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是解决方案:
http://labs.qt.nokia.com/2010/02/ 23/不可预测的执行/
Here is the solution:
http://labs.qt.nokia.com/2010/02/23/unpredictable-exec/