QMessageBox in initializeGL calls initializeGL one more time
Code:
void MyGlWidget::initializeGL() {
try {
throw std::exception();
} catch(...) {
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:
Code:
void MyGlWidget::initializeGL() {
if(in_initializeGL_)
return;
in_initializeGL_ = true;
try {
throw std::exception();
} catch(...) {
tr("Exception occured"));
}
in_initializeGL_ = false;
}
But this leads to crash. So I decided to show error in paintGL()(it also shows 2 messageboxes):
Code:
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()";
}
}
This solves the problem but the code is ugly. Is there a more nice solution of this problem?
Re: QMessageBox in initializeGL calls initializeGL one more time
Does this double showing of QMessageBox also happens when you construct the messagebox with a NULL parent?
Re: QMessageBox in initializeGL calls initializeGL one more time
Yes.
The call stack is(from down to up):
...
initializeGL()
updateGL()
QMessageBox::critical()
initializeGL()
Re: QMessageBox in initializeGL calls initializeGL one more time
hmm... my guess is that it has to do with QMessageBox showing it self, while you are in a paintEvent() - that maybe forces a general paintEvent() on all the applications visible widgets, resulting in a recursive call.
But that is only a guess.
Re: QMessageBox in initializeGL calls initializeGL one more time
Opening the QMessageBox using one of the static functions starts a new event loop. This is an Unpredictable exec() issue.
[Solved] QMessageBox in initializeGL calls initializeGL one more time
Thanks! Nice article and solution.
Code:
void MyGlWidget::initializeGL() {
try {
throw std::exception();
} catch(...) {
getExceptionMessage(&exception_msg_);
"Exception",
exception_msg_,
this);
msgbox->open(0, 0);
}
}
Don't forget to use "new QMessageBox", because "QMessageBox msgbox;" will be deleted on scope exit. open() doesn't block the execution.