[Solved]QDialog : How to return from exec method programmatically in static singleton class
-
Hello there,
I am developing Qt application (Qt version 4.7.3) on SBC6000x board.
I have a MessageBox class derived from QDialog. I have made this class singleton.
Whenever a messagebox is to be show I am using .exec method to show it.
There are few places where I need to show messageboxes one after another.
So, to show new messagebox, I have to close previous one and show new one.
e.g. When Messagebox is open and at same time I receive an error from background I have to close the messagebox which is currently shown and show the one with error.
To closes previous dialog I have exposed CloseDlg method from messagebox class and trying to close it.
Inside this CloseDlg I am emitting finished signal.
@void CMsgBox::CloseDlg()
{
if (NULL != CMsgBox::m_msgBox)
{
if(CMsgBox::m_msgBox->isVisible())
{
emit CMsgBox::m_msgBox->finished(0);
//QApplication::processEvents();
}
}
}@and calling it as
@CMsgBox::CloseDlg();@
My show method is :-
@int CMsgBox::showMsgBox(Icon icon, const QString &textMsg, const QString &okBtnText)
{
if (CMsgBox::m_msgBox == NULL)
{
CMsgBox::m_msgBox = new CMsgBox();
}
CMsgBox::m_msgBox->setText(textMsg);
CMsgBox::m_msgBox->setIcon(icon);
CMsgBox::m_msgBox->setOkBtnText(okBtnText);
CMsgBox::m_msgBox->exec();return CMsgBox::m_msgBox->m_btnPressed; //return, unblock the call
}@
Again when I call showMsgBox,it is showing me following warning.
QDialog::exec: Recursive call detectedProblem is, it doesn't return from previous exec call (unless we return, as commented above //).
I tried same with close(), accept(), reject() methods instead of finished() event but nothing worked.
What is the way to return from previous exe call and achieve above scenario? Any help is welcome.
Thanks,
Rajendra -
Why you don't use "QMessageBox":http://qt-project.org/doc/qt-4.7/QMessageBox.html ? This class has a static methods for displaing a text for information, warning, question messages.
-
I found the solution for this.
Please refer to:
http://stackoverflow.com/questions/13817016/how-to-return-from-exec-method-programmatically-in-static-singleton-class