0

I am new to QtDesigner/Pyside (and stackoverflow). I have a QtDesigner interface that previews well. I run it through pyside-uic with no "stub" external signals, and it works fine (doesn't do much!). When I add external signals, I get problems. I have looked through all references to Signals/Slots that seem likely, but nothing points to my problem. I have googled the error message, also with minimal results. After two days of head-banging I have concluded that whatever I am doing is so dumb it doesn't normally warrant a question! Any pointers would be much appreciated. The Ui_tunerSym parent class is around 600 lines, automatically generated from pyside.

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Created on Mon May 05 10:01:00 2014

@author: Gordon
"""

from PySide import QtCore, QtGui
#import UI produced by QtDesigner after running through: pyside-uic -x TunerSymWindow.ui -o ui_tunerSym.py
from ui_tunerSym import Ui_tunerSym

# subclass my UI class
class tView(Ui_tunerSym):
    def __init__(self):
        QtCore.QObject.connect(self.coarse_commandLinkButton, QtCore.SIGNAL("clicked()"), self.execute_coarse_tune)
        QtCore.QObject.connect(self.fine_commandLinkButton, QtCore.SIGNAL("clicked()"), self.execute_fine_tune)
        QtCore.QMetaObject.connectSlotsByName(tunerSym)

    def execute_coarse_tune(self):
        print "Coarse tune button pushed"

    def execute_fine_tune(self):
        print "Fine tune button pushed"

#example from web site used as basis
#QtCore.QObject.connect(button, QtCore.SIGNAL('clicked()'), someFunc)

#  copied from ui_tunerSym.pi. Shows the buttons and signals are in fact there...
#    QtCore.QObject.connect(self.coarse_commandLinkButton, QtCore.SIGNAL("clicked()"), tunerSym.execute_coarse_tune)
#    QtCore.QObject.connect(self.fine_commandLinkButton, QtCore.SIGNAL("clicked()"), tunerSym.execute_fine_tune)
#    QtCore.QMetaObject.connectSlotsByName(tunerSym)


if __name__ == '__main__':
    import sys
    app = QtGui.QApplication(sys.argv)
    frame = tView()
    frame.show()
    app.exec_()

# throws the following error:
# AttributeError: 'tView' object has no attribute 'coarse_commandLinkButton'
  • You're not running init of the parent class. – M4rtini May 07 '14 at 09:07
  • Thanks for the pointer- at least I am getting a different error now! I modified my code: # subclass my UI class class tView(Ui_tunerSym): def __init__(self): Ui_tunerSym.setupUi(self,tView) QtCore.QObject.connect(self.coarse_commandLinkButton, QtCore.SIGNAL("clicked()"), self.execute_coarse_tune) QtCore.QObject.connect(self.fine_commandLinkButton, QtCore.SIGNAL("clicked()"), self.execute_fine_tune) QtCore.QMetaObject.connectSlotsByName(tunerSym) Now I get the error:'tView' object has no attribute 'setObjectName' – user3608541 May 07 '14 at 14:03
  • add `super(tView, self).__init__()` at the start, you're still not calling init, this will do it. – M4rtini May 07 '14 at 15:48
  • I added an init for it, and also the setupUi(self,tView) in the init of my subclass. I now get a different error: AttributeError: type object 'tView' has no attribute 'setObjectName' – user3608541 May 08 '14 at 00:27
  • Many hours of research still have not resolved the problem. I think it must be in the way the instance is set up from the class. I have learned a lot about how this is done, including the user of super(). But ultimately I still cannot bind an event from Qt to external code. Perhaps I can find a good simple (and complete) example. Most examples give only snips, not the entire project. My code matches the snips, but still does not work! – user3608541 May 08 '14 at 13:36
  • can you update the question with current code? And add a link to a pastebin (or similar) with the code of the ui_tuneSym code ( i assume it's a bit long to put here). And I'll have a look at it later today. – M4rtini May 08 '14 at 14:16

0 Answers0