Hi all,

How does one connect dialogs to a parent object to receive any signals they may emit?

This doesn't work:
                dialog = Foo()
                self.connect(dialog, QtCore.SIGNAL("foo(string)"), 
self.printString)

The attached code sample creates a dialog that emits a signal on init(). The main window tries to connect the dialog, receive the signal, and call its assigned slot. Seems like it should work, but of course it doesn't.

I'm sure I'm overlooking something simple.  Thanks in advance!
Scott



#!/usr/bin/env python

import sys
from PyQt4 import QtCore, QtGui

class Foo(QtGui.QDialog):
	def __init__(self, parent=None):
		QtGui.QDialog.__init__(self)
		self.okButton           = QtGui.QPushButton(self.tr("OK"))
		self.okButton.setDefault(True)
		self.closeButton        = QtGui.QPushButton(self.tr("Close"))
		self.formLayout         = QtGui.QVBoxLayout()
		self.formLayout.addWidget(self.okButton)
		self.formLayout.addWidget(self.closeButton)
		self.setLayout(self.formLayout)
		self.connect(self.okButton, QtCore.SIGNAL("clicked()"), self, QtCore.SLOT("accept()"))
		self.connect(self.closeButton, QtCore.SIGNAL("clicked()"), self, QtCore.SLOT("close()"))

		self.emitSignal()


	def emitSignal(self):
		print "emitSignal()..."
		self.emit(QtCore.SIGNAL("foo(string)"), "signal: this is foo")



class MainWindow(QtGui.QMainWindow):
	def __init__(self):
		QtGui.QMainWindow.__init__(self)

		self.displayDialog()

	def displayDialog(self):
		dialog = Foo()
		self.connect(dialog, QtCore.SIGNAL("foo(string)"), self.printString)

		if dialog.exec_():
			print "dialog executed"


	def printString(self, theString):
		print "theString: ", theString



if __name__ == "__main__":
	app = QtGui.QApplication(sys.argv)
	mainwindow = MainWindow()
	mainwindow.show()
	sys.exit(app.exec_())







_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Reply via email to