[PyQt] PyQt5.uic.loadUi sometimes fails when connecting signals

Roger Leigh rleigh at debian.org
Tue Jul 30 23:25:17 BST 2013


Hi all,

I'm getting this error when I use loadUi():

Traceback (most recent call last):
  File "./testui", line 26, in <module>
    t = Test()
  File "./testui", line 13, in __init__
    self.ui = uic.loadUi("test-broken.ui", self)
  File "/usr/lib/python3/dist-packages/PyQt5/uic/__init__.py", line 224, in loadUi
    return DynamicUILoader(package).loadUi(uifile, baseinstance, resource_suffix)
  File "/usr/lib/python3/dist-packages/PyQt5/uic/Loader/loader.py", line 72, in loadUi
    return self.parse(filename, resource_suffix, basedir)
  File "/usr/lib/python3/dist-packages/PyQt5/uic/uiparser.py", line 931, in parse
    actor(elem)
  File "/usr/lib/python3/dist-packages/PyQt5/uic/uiparser.py", line 856, in createConnections
    bound_signal.connect(slot)
SystemError: error return without exception set

I've narrowed this down to occuring when I've added custom slots in
the ui designer.  However, it doesn't always occur, and I can't see
any obvious reasons for failure.

I've attached the most minimal testcase I can make.  The testui
program just loads one of the two attached .ui files.  One works,
one fails.  The only difference is one line which changes which
slot gets used.  However, both slots are absolutely identical,
and I can't see any reason for the failure unless either of the
names is somehow "special".

The code from which the testcase was derived is here:
http://anonscm.debian.org/gitweb/?p=users/rleigh/ogcalc.git;a=tree;f=qt/python;h=0d60c1c99d0438096badb186a030f166202e1a98;hb=341b96685f3abe92e78fd7768fc5c5893ce5b5ee
(ogcalc-ui, ogcalc.ui, SpinBoxEntry.py).  In this example both
the reset and calculate callbacks cause the failure; removing the
signal connection for both makes the UI load.  But if I remove
widgets from the UI to get to the minimal example above, it
eventually will start working by the time I'm down to the
minimal example above.


Being relatively new to both Qt and PyQt, I'm unsure if this isn't
me doing something wrong, but I can't see anything obviously bad
here so I'm wondering if I'm tripping over some odd edge case in
how the signal autoconnection works.  Either way, I'd be very
keen to understand what's going wrong here.

I'm using Python 3.3/Qt 5.1/PyQt 5.0 on Debian (unstable, amd64).


Thanks all,
Roger

-- 
  .''`.  Roger Leigh
 : :' :  Debian GNU/Linux             http://people.debian.org/~rleigh/
 `. `'   Printing on GNU/Linux?       http://gutenprint.sourceforge.net/
   `-    GPG Public Key: 0x25BFB848   Please GPG sign your mail.
-------------- next part --------------
#!/usr/bin/python3

from PyQt5 import uic
from PyQt5.QtCore import pyqtSlot
from PyQt5.QtGui import (QFont, QIcon)
from PyQt5.QtWidgets import (QApplication, QMainWindow)

class Test(QMainWindow):
    def __init__(self):
        super(Test, self).__init__()

#        self.ui = uic.loadUi("test-ok.ui", self)
        self.ui = uic.loadUi("test-broken.ui", self)

    @pyqtSlot()
    def calculate(self):
        print("Calc")

    @pyqtSlot()
    def reset(self):
        print("Reset")

if __name__ == "__main__":
    import sys
    app = QApplication(sys.argv)
    t = Test()
    t.show()
    sys.exit(app.exec())
-------------- next part --------------
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>ogcalc</class>
 <widget class="QMainWindow" name="ogcalc">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>407</width>
    <height>123</height>
   </rect>
  </property>
  <property name="sizePolicy">
   <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
    <horstretch>0</horstretch>
    <verstretch>0</verstretch>
   </sizepolicy>
  </property>
  <property name="maximumSize">
   <size>
    <width>16777215</width>
    <height>16777215</height>
   </size>
  </property>
  <property name="windowTitle">
   <string>OG & ABV calculator</string>
  </property>
  <property name="windowIcon">
   <iconset>
    <normaloff>ogcalc.svg</normaloff>ogcalc.svg</iconset>
  </property>
  <widget class="QWidget" name="toplevel_layout">
   <property name="sizePolicy">
    <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
     <horstretch>0</horstretch>
     <verstretch>0</verstretch>
    </sizepolicy>
   </property>
   <layout class="QVBoxLayout" name="vertical_layout">
    <item>
     <widget class="QPushButton" name="reset">
      <property name="text">
       <string>Reset</string>
      </property>
     </widget>
    </item>
   </layout>
  </widget>
 </widget>
 <layoutdefault spacing="6" margin="11"/>
 <resources/>
 <connections>
  <connection>
   <sender>reset</sender>
   <signal>clicked()</signal>
   <receiver>ogcalc</receiver>
   <slot>calculate()</slot>
   <hints>
    <hint type="sourcelabel">
     <x>203</x>
     <y>102</y>
    </hint>
    <hint type="destinationlabel">
     <x>203</x>
     <y>61</y>
    </hint>
   </hints>
  </connection>
 </connections>
 <slots>
  <slot>calculate()</slot>
  <slot>reset()</slot>
 </slots>
</ui>
-------------- next part --------------
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>ogcalc</class>
 <widget class="QMainWindow" name="ogcalc">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>407</width>
    <height>123</height>
   </rect>
  </property>
  <property name="sizePolicy">
   <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
    <horstretch>0</horstretch>
    <verstretch>0</verstretch>
   </sizepolicy>
  </property>
  <property name="maximumSize">
   <size>
    <width>16777215</width>
    <height>16777215</height>
   </size>
  </property>
  <property name="windowTitle">
   <string>OG & ABV calculator</string>
  </property>
  <property name="windowIcon">
   <iconset>
    <normaloff>ogcalc.svg</normaloff>ogcalc.svg</iconset>
  </property>
  <widget class="QWidget" name="toplevel_layout">
   <property name="sizePolicy">
    <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
     <horstretch>0</horstretch>
     <verstretch>0</verstretch>
    </sizepolicy>
   </property>
   <layout class="QVBoxLayout" name="vertical_layout">
    <item>
     <widget class="QPushButton" name="reset">
      <property name="text">
       <string>Reset</string>
      </property>
     </widget>
    </item>
   </layout>
  </widget>
 </widget>
 <layoutdefault spacing="6" margin="11"/>
 <resources/>
 <connections>
  <connection>
   <sender>reset</sender>
   <signal>clicked()</signal>
   <receiver>ogcalc</receiver>
   <slot>reset()</slot>
   <hints>
    <hint type="sourcelabel">
     <x>203</x>
     <y>102</y>
    </hint>
    <hint type="destinationlabel">
     <x>203</x>
     <y>61</y>
    </hint>
   </hints>
  </connection>
 </connections>
 <slots>
  <slot>calculate()</slot>
  <slot>reset()</slot>
 </slots>
</ui>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20130730/d91a1791/attachment-0001.pgp>


More information about the PyQt mailing list