Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. [Solved]QDialog : How to return from exec method programmatically in static singleton class

[Solved]QDialog : How to return from exec method programmatically in static singleton class

Scheduled Pinned Locked Moved Mobile and Embedded
3 Posts 2 Posters 2.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rajendra
    wrote on 11 Dec 2012, 09:01 last edited by
    #1

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

    Thanks,
    Rajendra

    1 Reply Last reply
    0
    • H Offline
      H Offline
      Hostel
      wrote on 11 Dec 2012, 13:17 last edited by
      #2

      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.

      1 Reply Last reply
      0
      • R Offline
        R Offline
        Rajendra
        wrote on 14 Dec 2012, 04:57 last edited by
        #3

        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

        1 Reply Last reply
        0

        1/3

        11 Dec 2012, 09:01

        • Login

        • Login or register to search.
        1 out of 3
        • First post
          1/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved