[PyQt] Trouble with uic.loadUi and connectSlotsByName

Peter O'Malley ooomalley at gmail.com
Sat May 15 22:55:42 BST 2010


Hello,

I've created a simple window in Designer but can't get the
connectSlotsByName function to connect up the button correctly when I've
loaded the UI with uic.loadUi. I can connect the button manually, or I can
use pyuic and it works, but I can't for the life of me figure out why this
won't connect. I've looked all through the mailing list archives and google,
but no I can't find my way out of it.

The code is attached, with relevant sections below.

Here's the relevant code with loadUi:

class TestWindow (QtGui.QMainWindow):
    def __init__(self):
        QtGui.QMainWindow.__init__(self)
        self.ui = uic.loadUi("test.ui")
        QtCore.QMetaObject.connectSlotsByName(self)
        #self.ui.maxButton.clicked.connect(self.on_maxButton_clicked)
        self.ui.show()

    @QtCore.pyqtSlot()
    def on_maxButton_clicked(self):
        print("max!")



Here is the working bit done with a file created by pyuic:

import testui

class TestWindow (QtGui.QMainWindow):
    def __init__(self):
        QtGui.QMainWindow.__init__(self)
        self.ui = testui.Ui_MainWindow()
        self.ui.setupUi(self)
        self.show()

    @QtCore.pyqtSlot()
    def on_maxButton_clicked(self):
        print("max!")



Thanks,
Peter O'Malley
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20100515/c2239b32/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: with-loadui.py
Type: application/octet-stream
Size: 530 bytes
Desc: not available
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20100515/c2239b32/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.ui
Type: application/octet-stream
Size: 2417 bytes
Desc: not available
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20100515/c2239b32/attachment-0001.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: testui.py
Type: application/octet-stream
Size: 2966 bytes
Desc: not available
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20100515/c2239b32/attachment-0002.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: with-pyuic.py
Type: application/octet-stream
Size: 444 bytes
Desc: not available
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20100515/c2239b32/attachment-0003.obj>


More information about the PyQt mailing list