<?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[Is there a way to avoid pyuic5 generating connectSlotsByName() automatically?]]></title><description><![CDATA[<p dir="auto">I'm using Qt Designer to design UI of my application, and using pyuic5 to transfer UI files to python code. Code generated by pyuic5 would be like:</p>
<pre><code># mainwindow.py
from PyQt5 import QtCore, QtGui, QtWidgets

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(600, 400)
        self.tableWidget = QtWidgets.QTableWidget(MainWindow)
        self.tableWidget.setObjectName("tableWidget")
        self.tableWidget.setColumnCount(10)
        self.tableWidget.setRowCount(10)
        # hide QTableWidgetItem generation code here
        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        # hide some code here
</code></pre>
<p dir="auto">In general, I need to create a new class which is derived from the class above to realize the response of every widget. My code would be like:</p>
<pre><code># mymainwindow.py
from PyQt5 import QtCore, QtWidgets
from mainwindow import Ui_MainWindow

class MyMainWindow(QtWidgets.QDialog, Ui_MainWindow):
    def __init__(self, parent=None):
        super(MyMainWindow, self).__init__(parent)
        self.data = read_list_from_external_file()
        self.setupUi(self)

    def setupUi(self, my_mainwindow):
        super(MyDialog, self).setupUi(my_mainwindow)
        for row in range(self.tableWidget.rowCount()):
            for col in range(self.tableWidget.columnCount()):
                self.tableWidget.setItem(row, col, QtWidgets.QTableWidgetItem(self.data[row][col]))

    @QtCore.pyqtSlot(int, int)
    def on_tableWidget_cellChanged(self, row, col):
        # some response on cell changed
</code></pre>
<p dir="auto">In my code, the slot method <code>on_tableWidget_cellChanged()</code> will be executed when I fill in <code>tableWidget</code>, but I don't want to do that in setup stage. The key point is that <code>connectSlotsByName()</code> needs to be executed after setup stage. Of course I can use <code>tableWidget.blockSignals()</code>, or give up using decorator and connect manually. But actually there are dozens of widgets in my application, neither solution looks like the "best" one in my mind. I expect a way to avoid generating <code>connectSlotsByName()</code> automatically, then I can add it in the end of <code>setupUi()</code> of <code>MyMainWindow</code> manually.<br />
Then I found in Qt Designer, there is a option to control whether <code>connectSlotsByName()</code> is added in the code.<br />
<img src="https://ddgobkiprc33d.cloudfront.net/b1a6bfb8-5931-471d-a911-b0304e805d17.png" alt="671dc7b4-cebf-4b79-acce-c54103e59d44-image.png" class=" img-fluid img-markdown" /><br />
If I uncheck this option, the header of .ui file will be modified from</p>
<pre><code>&lt;ui version="4.0"&gt;
</code></pre>
<p dir="auto">to</p>
<pre><code>&lt;ui version="4.0" connectslotsbyname="false"&gt;
</code></pre>
<p dir="auto">But it seems like pyuic5 doesn't recognize this change. <code>connectSlotsByName()</code> is still there. Is there a way  to avoid pyuic5 generating <code>connectSlotsByName()</code> automatically? Or is there an "elegant" way to avoid slot methods executing in setup stage?</p>
]]></description><link>https://forum.qt.io/topic/134578/is-there-a-way-to-avoid-pyuic5-generating-connectslotsbyname-automatically</link><generator>RSS for Node</generator><lastBuildDate>Fri, 10 Jul 2026 10:18:29 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/134578.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 23 Feb 2022 11:47:34 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Is there a way to avoid pyuic5 generating connectSlotsByName() automatically? on Thu, 24 Feb 2022 02:34:41 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a> <a class="plugin-mentions-user plugin-mentions-a" href="/user/sgaist">@<bdi>SGaist</bdi></a><br />
Thanks for your suggestions!<br />
I have thought of the solution you mentioned. Maybe it's the best way so far (before this pyuic5 bug fixed).</p>
]]></description><link>https://forum.qt.io/post/704047</link><guid isPermaLink="true">https://forum.qt.io/post/704047</guid><dc:creator><![CDATA[Qinhan Hou]]></dc:creator><pubDate>Thu, 24 Feb 2022 02:34:41 GMT</pubDate></item><item><title><![CDATA[Reply to Is there a way to avoid pyuic5 generating connectSlotsByName() automatically? on Wed, 23 Feb 2022 19:05:14 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">You can also use the blockSignals method however having explicit connections will be simpler in the long run.</p>
]]></description><link>https://forum.qt.io/post/704004</link><guid isPermaLink="true">https://forum.qt.io/post/704004</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Wed, 23 Feb 2022 19:05:14 GMT</pubDate></item><item><title><![CDATA[Reply to Is there a way to avoid pyuic5 generating connectSlotsByName() automatically? on Wed, 23 Feb 2022 12:42:15 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/qinhan-hou">@<bdi>Qinhan-Hou</bdi></a><br />
If you say unchecking that option does <em>not</em> seem to work from PyQt5 (I don't know whether it does or not, I'm surprised it does not but if that is what you say), then the best i can suggest is: do <em>not</em> name your slots in the <code>connectSlotsByName()</code> way, pick anything else.  Then it won't find the slots to connect (which is fine) and you can do your own manual connections when you choose to.</p>
]]></description><link>https://forum.qt.io/post/703953</link><guid isPermaLink="true">https://forum.qt.io/post/703953</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Wed, 23 Feb 2022 12:42:15 GMT</pubDate></item></channel></rss>