<?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[Let closeEvent interract with Model&#x2F;View]]></title><description><![CDATA[<p dir="auto">Hi all,</p>
<p dir="auto">I have a working model table based.<br />
The user interacts with the model though a <em>QDialog</em> (child of the main <em>QMainWindow</em>).<br />
I'd like to update a file (with some of the table's data) only when the user closes this subwindow and not when data is changed.</p>
<p dir="auto">The idea is to reimplement the <em>QCloseEvent</em> adding an emitting signal that calls the slot (method) to make all the necessary stuff.<br />
My problem is related to the "architecture"; I can't find a way to make this signal visible to both the dialog and the data, here the skeleton code:</p>
<p dir="auto">_data.py</p>
<pre><code>class TableModel(QAbstractTableModel):
    ...
    def data(self, ...):
       ....

    def setData(self, ...):
      ....

class Data(QObject):
    table_changed = pyqtSignal(object)
    data_updated = pyqtSignal()

   def __init__(self, ...):
   ...

   def update_to_model(self):
   ....

   def update_file(self, ...):
   ....
   

class DialogData(QDialog):
    def __init__(self, data):
    ...
    view = QTableView(self)
    ...
    vbox = QVBoxLayout(self)
    vbox.addWidget(view)
    ...

def closeEvent(self, event):
    # I can't (of course) emit this signal - out of scope
    self.data_updated.emit()
    ...
    event.accept()
</code></pre>
<p dir="auto">_main_window.py</p>
<pre><code>class MainWindow(QMainWindow):
    def __init(self, data)
    ...
    self.dialog_window = DialogData(data)
    ...
</code></pre>
<p dir="auto">_main.py</p>
<pre><code>def main()
    ...
    # here where model il created and managed
    data = Data()
    # here where main window is created and managed
    main_window = MainWindow(data)
    ...
    # connect signal to the slot
    data.data_updated.connect(data.update_file)
    ...
</code></pre>
<p dir="auto">I hope that the sketch is clear.</p>
<p dir="auto">What are the necessary changes to my architecture to let the <em>closeEvent</em> within the <em>dialog_window</em> emit a signal to be used from the slot <em>update_file</em>?</p>
<p dir="auto">Many thanks to all.</p>
]]></description><link>https://forum.qt.io/topic/134411/let-closeevent-interract-with-model-view</link><generator>RSS for Node</generator><lastBuildDate>Mon, 20 Apr 2026 11:45:19 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/134411.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 17 Feb 2022 10:32:26 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Let closeEvent interract with Model&#x2F;View on Thu, 17 Feb 2022 10:41:03 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/superaga">@<bdi>superaga</bdi></a> said in <a href="/post/702968">Let closeEvent interract with Model/View</a>:</p>
<blockquote>
<p dir="auto">data.data_updated.connect(data.update_file)</p>
</blockquote>
<p dir="auto">What is the reasoning behind this? Why do you connect a signal and slot from same instance?</p>
<p dir="auto">Back to your question: override closeEvent, define a signal in MainWindow, emit that signal in closeEvent and connect that signal to the slot:</p>
<pre><code>main_window.YOUR_SIGNAL.connect(data.update_file)
</code></pre>
]]></description><link>https://forum.qt.io/post/702972</link><guid isPermaLink="true">https://forum.qt.io/post/702972</guid><dc:creator><![CDATA[jsulm]]></dc:creator><pubDate>Thu, 17 Feb 2022 10:41:03 GMT</pubDate></item><item><title><![CDATA[Reply to Let closeEvent interract with Model&#x2F;View on Thu, 17 Feb 2022 11:08:18 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jsulm">@<bdi>jsulm</bdi></a> many thanks for your answer.</p>
<p dir="auto">Sorry that is a typo (let me correct it...)</p>
<p dir="auto">Your answer makes sense and clarify the point.</p>
<p dir="auto">Many thanks!</p>
]]></description><link>https://forum.qt.io/post/702980</link><guid isPermaLink="true">https://forum.qt.io/post/702980</guid><dc:creator><![CDATA[superaga]]></dc:creator><pubDate>Thu, 17 Feb 2022 11:08:18 GMT</pubDate></item><item><title><![CDATA[Reply to Let closeEvent interract with Model&#x2F;View on Thu, 17 Feb 2022 10:41:03 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/superaga">@<bdi>superaga</bdi></a> said in <a href="/post/702968">Let closeEvent interract with Model/View</a>:</p>
<blockquote>
<p dir="auto">data.data_updated.connect(data.update_file)</p>
</blockquote>
<p dir="auto">What is the reasoning behind this? Why do you connect a signal and slot from same instance?</p>
<p dir="auto">Back to your question: override closeEvent, define a signal in MainWindow, emit that signal in closeEvent and connect that signal to the slot:</p>
<pre><code>main_window.YOUR_SIGNAL.connect(data.update_file)
</code></pre>
]]></description><link>https://forum.qt.io/post/702972</link><guid isPermaLink="true">https://forum.qt.io/post/702972</guid><dc:creator><![CDATA[jsulm]]></dc:creator><pubDate>Thu, 17 Feb 2022 10:41:03 GMT</pubDate></item></channel></rss>