<?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[Beginner : getting the output of a Widget once closed ?]]></title><description><![CDATA[<p dir="auto">Hi,<br />
I'm really new in Qt and in GUI development.<br />
I use PyQt5 and I need to ask 3 times the user to select a value in a predefined set.</p>
<p dir="auto">Here's the class i developed to handle this task :</p>
<pre><code>class session_window(QWidget):
    def __init__(self):
        super().__init__()
        self.resize(600,300)
        self.setWindowModality(Qt.ApplicationModal)

        d = QFormLayout()
   
        self.sat = QComboBox()
        self.sat.addItems(['A', 'B', 'C'])
        d.addRow(QLabel('Choose a value : '), self.sat)
        
        self.ok_button = QPushButton('Ok', clicked=self.next)
        d.addRow(None, self.ok_button)
        
        self.setLayout(d)
        self.show()
        
    def next(self):
        print('clicked !')
        my_list.append(self.sat.currentText())
        self.close()
</code></pre>
<p dir="auto">In the above example, my_list is a global variable that will store the successive results.</p>
<p dir="auto">And in my code I have something like :</p>
<pre><code>for k in range(3):
            print('- Asking session %d/3...' % (k+1))
            x = session_window()
</code></pre>
<p dir="auto">This does not work and I know that it is very bad design.. but i don't know how to handle that...<br />
Could you please tell me what kind of keywords I should read in the Qt doc to understand how to code this properly ?</p>
<p dir="auto">My example is very simplified but in reality :</p>
<ul>
<li>some additional information will be needed at each iteration (so I will need to add additional widget in my class)</li>
<li>the number of iteration will be determined during the code execution and is not hard-coded</li>
</ul>
<p dir="auto">Thanks a lot for your answer and sorry for the very basic question...</p>
<p dir="auto">BR</p>
<p dir="auto">Pierre</p>
]]></description><link>https://forum.qt.io/topic/132079/beginner-getting-the-output-of-a-widget-once-closed</link><generator>RSS for Node</generator><lastBuildDate>Tue, 04 Aug 2026 22:02:39 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/132079.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 17 Nov 2021 17:46:46 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Beginner : getting the output of a Widget once closed ? on Thu, 18 Nov 2021 18:48:00 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/donutman">@<bdi>DonutMan</bdi></a> said in <a href="/post/690700">Beginner : getting the output of a Widget once closed ?</a>:</p>
<blockquote>
<p dir="auto">I was a bit surprised that these objects are still available once the self.close() is called. I somehow expected that the object will be destroyed just after being closed...</p>
</blockquote>
<p dir="auto">Unless you set the deleteOnClose properly, they should not.</p>
<p dir="auto">Note that the Qt parent child system does not forbid you to do same memory handling.</p>
<p dir="auto">A child will live as long as it parent so if you create a lot of dialogs all the time without cleaning them, they will still eat your memory.</p>
]]></description><link>https://forum.qt.io/post/690716</link><guid isPermaLink="true">https://forum.qt.io/post/690716</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Thu, 18 Nov 2021 18:48:00 GMT</pubDate></item><item><title><![CDATA[Reply to Beginner : getting the output of a Widget once closed ? on Thu, 18 Nov 2021 18:10:23 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mrjj">@<bdi>mrjj</bdi></a> Hi, thanks a lot for your answer :)</p>
]]></description><link>https://forum.qt.io/post/690712</link><guid isPermaLink="true">https://forum.qt.io/post/690712</guid><dc:creator><![CDATA[DonutMan]]></dc:creator><pubDate>Thu, 18 Nov 2021 18:10:23 GMT</pubDate></item><item><title><![CDATA[Reply to Beginner : getting the output of a Widget once closed ? on Thu, 18 Nov 2021 16:55:30 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/donutman">@<bdi>DonutMan</bdi></a> said in <a href="/post/690700">Beginner : getting the output of a Widget once closed ?</a>:</p>
<blockquote>
<p dir="auto">Do I need to explicitly destroy them once I got the fields I wanted ?</p>
</blockquote>
<p dir="auto">Hi<br />
Well Qt has an owner system.<br />
<a href="https://doc.qt.io/qt-5/objecttrees.html" target="_blank" rel="noopener noreferrer nofollow ugc">https://doc.qt.io/qt-5/objecttrees.html</a></p>
<p dir="auto">which means, if you assign a parent, it will clean it up when the parent is deleted.</p>
<p dir="auto">However,  you can manually clean it up after use, if you wish.<br />
but instead of a c++ delete then use<br />
<a href="https://doc.qt.io/qt-5/qobject.html#deleteLater" target="_blank" rel="noopener noreferrer nofollow ugc">https://doc.qt.io/qt-5/qobject.html#deleteLater</a></p>
]]></description><link>https://forum.qt.io/post/690710</link><guid isPermaLink="true">https://forum.qt.io/post/690710</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Thu, 18 Nov 2021 16:55:30 GMT</pubDate></item><item><title><![CDATA[Reply to Beginner : getting the output of a Widget once closed ? on Thu, 18 Nov 2021 16:19:06 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sgaist">@<bdi>SGaist</bdi></a><br />
Hello, thank you very much for your answer !<br />
Finally I though adding setWindowModality(Qt.ApplicationModal) will stop the execution of code until the window returns but my reasoning was false.<br />
Indeed a QWizard object does exactly what I was expecting.<br />
I also tried playing with QDialog objects which behave in a similar way (ie : the code stop until the windows is closed).</p>
<p dir="auto">I was a bit surprised that these objects are still available once the self.close() is called. I somehow expected that the object will be destroyed just after being closed...</p>
<p dir="auto">Do I need to explicitly destroy them once I got the fields I wanted ?<br />
My application is very small but I want to adopt the good practices ^^</p>
<p dir="auto">Anyway, thanks a lot for your answer</p>
<p dir="auto">BR</p>
<p dir="auto">Pierre</p>
]]></description><link>https://forum.qt.io/post/690700</link><guid isPermaLink="true">https://forum.qt.io/post/690700</guid><dc:creator><![CDATA[DonutMan]]></dc:creator><pubDate>Thu, 18 Nov 2021 16:19:06 GMT</pubDate></item><item><title><![CDATA[Reply to Beginner : getting the output of a Widget once closed ? on Wed, 17 Nov 2021 19:18:39 GMT]]></title><description><![CDATA[<p dir="auto">Hi and welcome to devnet,</p>
<p dir="auto">Sounds like you could use a <a href="https://doc.qt.io/qt-5/qwizard.html" target="_blank" rel="noopener noreferrer nofollow ugc">QWizard</a>.</p>
<p dir="auto">That way you can create the widgets you need and show them as you need. Once the wizard is finished you can retrieve whatever field you want.</p>
]]></description><link>https://forum.qt.io/post/690552</link><guid isPermaLink="true">https://forum.qt.io/post/690552</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Wed, 17 Nov 2021 19:18:39 GMT</pubDate></item></channel></rss>