In Pyqt5, Why Signal Can't Connect A Slot In A External Class?
Background I'm using signals to implement MVC in PyQt5. There are many interfaces in one program. Each page has a corresponding controller, and all the controllers are finally put
Solution 1:
There is no persistent reference to login_controller
: you create it as a local variable, then the init
function returns, python's garbage collector is unable to find any reference to it, so it deletes it.
The solution is simple:
definit(self):
self.login_controller = login_control.Controller(
self._view, self._stu.name, self._stu.password)
self._view.login_signal.connect(self.login)
Please consider that, while using an MVC pattern is generally a good idea, it should be done to improve the quality of your project structure by providing better abstraction and offering easier debugging without overcomplicating things.
For instance, your Controller
class (which also has a name that is really too similar to the other one), is almost superfluous, as your main Controll
should be enough.
Post a Comment for "In Pyqt5, Why Signal Can't Connect A Slot In A External Class?"