I'm trying to display information in a text browser with the push of a button in my QGIS plugin. The .ui is created using PyQt4 (button's object name is calcConso). No error message, but the button isn't connecting. The button simply displays values returned by my stats function, but the function itself isn't actually called anywhere. If it should be, I don't see where yet.

Any ideas what's missing?

def initGui(self):
# connect button to calculation function
    QObject.connect(self.dlg.ui.calcConso, SIGNAL("clicked()"), self.buttonClicked)

def buttonClicked(self):
    global stats, values
    self.dlg.setTextBrowser( str(stats, values) )

def stats(self):
    global stats, values
    return stats, values

in a separate dialog class i've defined clearTextBrowser() and setTextBrowser(), which is imported.

def setTextBrowser(self, output):

def clearTextBrowser(self):
  • I don't see anything wrong with your connect statement. How do you know it's not connecting? You can test the return value of the QObject.connect statement to see if it is True. Perhaps your setTextBrowser method is not doing what you think it should. – gsherman Feb 28 '14 at 5:53
  • how exactly should i integrate this test into my program? where would I see the results of a print statement? – user25976 Mar 1 '14 at 0:11

To test your connection:

from PyQt4.QtGui import QMessageBox
result = QObject.connect(self.dlg.ui.calcConso, SIGNAL("clicked()"), self.buttonClicked)
QMessageBox.information(None, 'Connection result', "Connect returned %s" % result)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.