First, when signals have no arguments things are pretty simple. Take this example:
QObject.connect(self.timer, SIGNAL("timeout()"), self.processStatus)
As you can see, in PyQt you pass string representations of function prototypes in when setting up the connection between a signal and slot. In this case you can just define a simple python function to hook this baby up and the timer will send out the signal when the timeout occurs:
def processStatus(self):
# Do something useful here...
Now what if you are hooking up to a SIGNAL that has arguments from a core C++ based library, either from QT or from QGIS? Still pretty simple:
QObject.connect(self.view, SIGNAL("customContextMenuRequested(const QPoint &)"), self.processCustomMenu)
Note that the string in the SIGNAL definition must match exactly with the signature of the function... a missed space will send you on a wild debugging ride. From here we can just write a simple processCustomMenu function and expect to receive the point from QT as an argument.
def processCustomMenu(self, position):
# Do something useful with the position...
OK... pretty straight forward so far. Now were it gets slightly tricky is if you are defining your own signals and slots and not interacting with QT or QGIS at all. In this case you can follow the simple scenario for signals with no arguments, but if you are defining your own signal that has arguments you have to employ the following trick:
QObject.connect(self.testThread, SIGNAL("testFinished(PyQt_PyObject)"), self.testFinishedFromThread)
As you can see you have to insert a special PyQt_PyObject in the function prototype. This allows you to pass any arbitrary python object in the signal. On the receiving end you can expect to get your argument.
def testFinishedFromThread(self,success):
print "Model Finished with success = ", success
self.emit(SIGNAL("testFinished(PyQt_PyObject)"),success)