How to close all Dialogs opened on my app on exit...



  • Well I need to close all QDialogs opened in my application on exit!
    But some of this Dialogs still open after close the application...
    Have some Dialog that I can set the "QWidget *parent", but someone I can't do that, because I show the Dialog in class extended from QObject!

    How can I make all open QDIalogs close?!

    Thanks


  • Moderators

    [quote author="dcbasso" date="1355573304"]but someone I can't do that, because I show the Dialog in class extended from QObject![/quote]

    This is stange. You should still be able to assign a parent. And if it's really impossible, then store pointers to all rouge QDialogs you have and destroy them on qApp->quit().



  • I can't because the QObject is not QWidget, and the Constructor of QDialog, the parent is "QWidget", so inside the QOBject I could not set the parent!

    I have a Factory to build and show this Dialogs... as you can see here:

    @
    #include "caixadialogo.h"
    #include "singletonsession.h"

    CaixaDialogo::CaixaDialogo(QObject parent) :
    QObject(parent)
    {
    }
    QMessageBox
    CaixaDialogo::getConfiguradoComSucesso(QString mensagem, QWidget parent)
    {
    QMessageBox
    msgBox = new QMessageBox( parent );
    msgBox->setText( mensagem.toAscii() );
    msgBox->setIcon(QMessageBox::Information);
    return msgBox;
    }
    QMessageBox* CaixaDialogo::getErroAoConfigurar(QString mensagem, QWidget parent)
    {
    QMessageBox
    msgBox = new QMessageBox( parent );
    msgBox->setText( mensagem.toAscii() );
    msgBox->setIcon(QMessageBox::Warning);
    return msgBox;
    }
    QMessageBox* CaixaDialogo::getMensagemSucesso(QString mensagem, QWidget parent)
    {
    QMessageBox
    msgBox = new QMessageBox( parent );
    msgBox->setText( mensagem.toAscii() );
    msgBox->setIcon(QMessageBox::Information);
    return msgBox;
    }
    QMessageBox* CaixaDialogo::getMensagemErro(QString mensagem, QWidget parent)
    {
    QMessageBox
    msgBox = new QMessageBox( parent );
    msgBox->setText( mensagem.toAscii() );
    msgBox->setIcon(QMessageBox::Warning);
    return msgBox;
    }
    QMessageBox* CaixaDialogo::getMensagemAviso(QString mensagem, QWidget parent)
    {
    QMessageBox
    msgBox = new QMessageBox( parent );
    msgBox->setText( mensagem.toAscii() );
    return msgBox;
    }
    @


  • Moderators

    Ugh, code is not in English. Ok, then. Either use the factory to delete all dialogs, or - say - make your main window into a singleton, and then assign that singleton as parent to all those widgets.



  • Hello

    I think you could achieve it by the SLOT closeAllWindows(). In your main application when accepting closeEvent, just call closeAllWindows(), maybe that could work.

    @void yourApplication::closeEvent(QCloseEvent *event)
    {
    closeAllWindows();
    event->accept();
    }@

    Nevertheless take a look to "this documentation on closeEvent":http://qt-project.org/doc/qt-4.8/qcloseevent.html

    Good luck!



  • bq. Have some Dialog that I can set the “QWidget *parent”, but someone I can’t do that, because I show the Dialog in class extended from QObject!

    Dialog without parent is not a good idea. If you derive your own class from QObject and an instance of that class is going to create a QDialog, nothing is holding you from adding a member variable of type "QWidget*" to your class to store the pointer to the parent dialog. So when the instance of your class (derived from QObject) is created, pass the parent pointer in constructor or via a separate setParentWidget(QWidtget *ptr)". Then, when the QDialog is created, use the pointer you stored before as the parent. And if you don't like this solution for whatever reason, you can still use "qApp()->activeWindow()" as parent for your QDialog...

    @class MyClass : public QObject
    {
    public:
    MyClass(QWidget *ptr)
    {
    m_parent = ptr;
    }

    private:
    QWidget *m_parent;

    void showDialog(void)
    {
        QDialog myDlg = new QDialog(m_parent);
        myDlg->exec();
    }
    

    };@


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.