<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[How to close all Dialogs opened on my app on exit...]]></title><description><![CDATA[<p dir="auto">Well I need to close all QDialogs opened in my application on exit!<br />
But some of this Dialogs still open after close the application...<br />
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!</p>
<p dir="auto">How can I make all open QDIalogs close?!</p>
<p dir="auto">Thanks</p>
]]></description><link>https://forum.qt.io/topic/22248/how-to-close-all-dialogs-opened-on-my-app-on-exit</link><generator>RSS for Node</generator><lastBuildDate>Sun, 12 Apr 2026 13:10:19 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/22248.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 15 Dec 2012 12:08:24 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How to close all Dialogs opened on my app on exit... on Sat, 15 Dec 2012 14:02:21 GMT]]></title><description><![CDATA[<p dir="auto">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!</p>
<p dir="auto">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 <em>or</em> 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()-&gt;activeWindow()" as parent for your QDialog...</p>
<p dir="auto">@class MyClass : public QObject<br />
{<br />
public:<br />
MyClass(QWidget *ptr)<br />
{<br />
m_parent = ptr;<br />
}</p>
<p dir="auto">private:<br />
QWidget *m_parent;</p>
<pre><code>void showDialog(void)
{
    QDialog myDlg = new QDialog(m_parent);
    myDlg-&gt;exec(&amp;#41;;
}
</code></pre>
<p dir="auto">};@</p>
]]></description><link>https://forum.qt.io/post/159753</link><guid isPermaLink="true">https://forum.qt.io/post/159753</guid><dc:creator><![CDATA[MuldeR]]></dc:creator><pubDate>Sat, 15 Dec 2012 14:02:21 GMT</pubDate></item><item><title><![CDATA[Reply to How to close all Dialogs opened on my app on exit... on Sat, 15 Dec 2012 13:52:20 GMT]]></title><description><![CDATA[<p dir="auto">Hello</p>
<p dir="auto">I think you could achieve it by the SLOT closeAllWindows(). In your main application when accepting closeEvent, just call closeAllWindows(), maybe that could work.</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/void">@<bdi>void</bdi></a> yourApplication::closeEvent(QCloseEvent *event)<br />
{<br />
closeAllWindows();<br />
event-&gt;accept();<br />
}@</p>
<p dir="auto">Nevertheless take a look to "this documentation on closeEvent":<a href="http://qt-project.org/doc/qt-4.8/qcloseevent.html" target="_blank" rel="noopener noreferrer nofollow ugc">http://qt-project.org/doc/qt-4.8/qcloseevent.html</a></p>
<p dir="auto">Good luck!</p>
]]></description><link>https://forum.qt.io/post/159751</link><guid isPermaLink="true">https://forum.qt.io/post/159751</guid><dc:creator><![CDATA[QMartin]]></dc:creator><pubDate>Sat, 15 Dec 2012 13:52:20 GMT</pubDate></item><item><title><![CDATA[Reply to How to close all Dialogs opened on my app on exit... on Sat, 15 Dec 2012 13:02:35 GMT]]></title><description><![CDATA[<p dir="auto">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.</p>
]]></description><link>https://forum.qt.io/post/159745</link><guid isPermaLink="true">https://forum.qt.io/post/159745</guid><dc:creator><![CDATA[sierdzio]]></dc:creator><pubDate>Sat, 15 Dec 2012 13:02:35 GMT</pubDate></item><item><title><![CDATA[Reply to How to close all Dialogs opened on my app on exit... on Sat, 15 Dec 2012 12:40:47 GMT]]></title><description><![CDATA[<p dir="auto">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!</p>
<p dir="auto">I have a Factory to build and show this Dialogs... as you can see here:</p>
<p dir="auto">@<br />
#include "caixadialogo.h"<br />
#include "singletonsession.h"</p>
<p dir="auto">CaixaDialogo::CaixaDialogo(QObject <em>parent) :<br />
QObject(parent)<br />
{<br />
}<br />
QMessageBox</em> CaixaDialogo::getConfiguradoComSucesso(QString mensagem, QWidget <em>parent)<br />
{<br />
QMessageBox</em> msgBox = new QMessageBox( parent );<br />
msgBox-&gt;setText(  mensagem.toAscii() );<br />
msgBox-&gt;setIcon(QMessageBox::Information);<br />
return msgBox;<br />
}<br />
QMessageBox* CaixaDialogo::getErroAoConfigurar(QString mensagem, QWidget <em>parent)<br />
{<br />
QMessageBox</em> msgBox = new QMessageBox( parent );<br />
msgBox-&gt;setText( mensagem.toAscii() );<br />
msgBox-&gt;setIcon(QMessageBox::Warning);<br />
return msgBox;<br />
}<br />
QMessageBox* CaixaDialogo::getMensagemSucesso(QString mensagem, QWidget <em>parent)<br />
{<br />
QMessageBox</em> msgBox = new QMessageBox( parent );<br />
msgBox-&gt;setText(  mensagem.toAscii() );<br />
msgBox-&gt;setIcon(QMessageBox::Information);<br />
return msgBox;<br />
}<br />
QMessageBox* CaixaDialogo::getMensagemErro(QString mensagem, QWidget <em>parent)<br />
{<br />
QMessageBox</em> msgBox = new QMessageBox( parent );<br />
msgBox-&gt;setText( mensagem.toAscii() );<br />
msgBox-&gt;setIcon(QMessageBox::Warning);<br />
return msgBox;<br />
}<br />
QMessageBox* CaixaDialogo::getMensagemAviso(QString mensagem, QWidget <em>parent)<br />
{<br />
QMessageBox</em> msgBox = new QMessageBox( parent );<br />
msgBox-&gt;setText( mensagem.toAscii() );<br />
return msgBox;<br />
}<br />
@</p>
]]></description><link>https://forum.qt.io/post/159741</link><guid isPermaLink="true">https://forum.qt.io/post/159741</guid><dc:creator><![CDATA[dcbasso]]></dc:creator><pubDate>Sat, 15 Dec 2012 12:40:47 GMT</pubDate></item><item><title><![CDATA[Reply to How to close all Dialogs opened on my app on exit... on Sat, 15 Dec 2012 12:35:03 GMT]]></title><description><![CDATA[<p dir="auto">[quote author="dcbasso" date="1355573304"]but someone I can't do that, because I show the Dialog in class extended from QObject![/quote]</p>
<p dir="auto">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-&gt;quit().</p>
]]></description><link>https://forum.qt.io/post/159739</link><guid isPermaLink="true">https://forum.qt.io/post/159739</guid><dc:creator><![CDATA[sierdzio]]></dc:creator><pubDate>Sat, 15 Dec 2012 12:35:03 GMT</pubDate></item></channel></rss>