Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to close all Dialogs opened on my app on exit...
QtWS25 Last Chance

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

Scheduled Pinned Locked Moved General and Desktop
6 Posts 4 Posters 4.6k 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.
  • D Offline
    D Offline
    dcbasso
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      [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().

      (Z(:^

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dcbasso
        wrote on last edited by
        #3

        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;
        }
        @

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          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.

          (Z(:^

          1 Reply Last reply
          0
          • Q Offline
            Q Offline
            QMartin
            wrote on last edited by
            #5

            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!

            1 Reply Last reply
            0
            • M Offline
              M Offline
              MuldeR
              wrote on last edited by
              #6

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

              };@

              My OpenSource software at: http://muldersoft.com/

              Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

              Go visit the coop: http://youtu.be/Jay...

              1 Reply Last reply
              0

              • Login

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