in main.py
def setNumberFormat2(self):
dialog = numberformatdlg2.NumberFormatDlg(self.format, self)
self.connect(dialog, SIGNAL("changed"), self.refreshTable)
dialog.show()
and in form.py:
class NumberFormatDlg(QDialog):
def __init__(self, format, parent=None):
.....
self.connect(buttonBox.button(QDialogButtonBox.Apply),
SIGNAL("clicked()"), self.apply)
self.connect(buttonBox, SIGNAL("rejected()"),
self, SLOT("reject()"))
self.setWindowTitle("Set Number Format (Modeless)")
def apply(self):
....
self.emit(SIGNAL("changed"))
According to the author:
Finally, we emit a changed signal, and as we have seen, this causes
the caller’s refreshTable() method to be called, which in turn formats
all the numbers in the table using the caller’s format dictionary.
When we emit, how does it know we which SLOT we want to apply? Essentially, if we have
self.connect(dialog, SIGNAL("changed"), self.refreshTable)
self.connect(dialog, SIGNAL("changed"), self.anotherMethod)
How does self.emit(...) know which slot we are applying? or am I missing some information?
Thanks.
self.emitdoesn’t “know” anything – it just fires the signal.The
self.connect()method is catching the signal and running the given function with the signal parameters.If you connect two functions to a signal, I think that both will run.
You probably shouldn’t do it, because it’ll make your code a bit unreadable.
changed_signalthat will call the other functions.