PyQt signals connect but do not invoke methods.. (PyQt4.8, Python 3.2)
Hey guys, i know the question doesn't make it clear enough (couldn't find how to explain the prob in a single line). I'm working on a project where i have a centralized gui included in a main class, with various components of the project made of composed objects of other classes (coded in separate files). To keep exchanging data, each object has the object of the main class composed in them as well (edit: will try the method E.Bendersky suggested). Thus the signals of each component are connected separately.
This is the connections code in the constructor for classA;
QtCore.QObject.connect(self.ui.pushButton, QtCore.SIGNAL("clicked()"), self.impAln)
QtCore.QObject.connect(self.ui.comboBox_2, QtCore.SIGNAL("currentIndexChanged(int)"), self.makeAlnTable)
QtCore.QObject.connect(self.ui.pushButton_2, QtCore.SIGNAL("clicked()"), self.reset)
The connections code in the constructor for classB;
QtCore.QObject.connect(self.ui.comboBox_3, QtCore.SIGNAL("currentIndexChanged(int)"), self.enableLineEdits)
QtCore.QObject.connect(self.ui.comboBox_4, QtCore.SIGNAL("currentIndexChanged(int)"), sel开发者_如何学JAVAf.enableLineEdits)
QtCore.QObject.connect(self.ui.comboBox_5, QtCore.SIGNAL("currentIndexChanged(int)"), self.enableLineEdits)
QtCore.QObject.connect(self.ui.pushButton_4, QtCore.SIGNAL("clicked()"), self.wrdMaker)
QtCore.QObject.connect(self.ui.pushButton_3, QtCore.SIGNAL("clicked()"), self.reset)
The problem is that when an instance of classA is created, the connections and signals work fine. But when an instance of classB is created, the respective signals don't work (buttons don't start methods etc; no error/exception is raised). I tried looking up online and in "Rapid Gui Programming with Python and Qt", but none cater to this specific problem.
Any help is greatly appreciated, thanks in advance..
Indeed, the question is far too vague IMHO. Without a concrete, minimal code sample that demonstrates the problem it will be very hard to help you.
I want to address one troubling thing you wrote though:
to keep exchanging data, each object has the object of the main class composed in them as well
This is almost certainly a bad idea, and exactly what Qt's signals and slots were designed to address without creating such coupling. You make all your objects know about some "main", central object - a design disaster waiting to happen. Why not exchange data with signals and slots, without this one extra composition?
This may sound off-topic, but I frequently found over-complicated designs to cause subtle programming errors that were hard to explain and debug before the design was untangled.
精彩评论