void MyGlWidget::initializeGL() {
try {
throw std::exception();
} catch(...) {
tr("Exception occured"));
}
}
void MyGlWidget::initializeGL() {
try {
throw std::exception();
} catch(...) {
QMessageBox::critical(this, tr("Exception"),
tr("Exception occured"));
}
}
To copy to clipboard, switch view to plain text mode
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(...) {
tr("Exception occured"));
}
in_initializeGL_ = false;
}
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;
}
To copy to clipboard, switch view to plain text mode
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()) {
exception_msg_);
exception_msg_.clear();
}
// rendering stuff
in_paintGL_ = false;
}
void MyGlWidget::initializeGL() {
try {
throw std::exception();
} catch(...) {
exception_msg_ = "Exception in initializeGL()";
}
}
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()";
}
}
To copy to clipboard, switch view to plain text mode
This solves the problem but the code is ugly. Is there a more nice solution of this problem?
Bookmarks