Important: Please read the Qt Code of Conduct -

[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)
    emit CMsgBox::m_msgBox->finished(0);

    and calling it as


    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();

    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 detected

    Problem 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.


  • Why you don't use "QMessageBox": ? This class has a static methods for displaing a text for information, warning, question messages.

Log in to reply