Issue
This is a vastly simplified version of what I have. Classes S, L, and O are three distinct UI's with some components in common, including [prev] and [next] pushbuttons.
When I move everything from class Broken's init() to main(), the prev and next buttons connect to their slots when clicked. However, in when they're in Broken, they won't. Broken does, however see the text of the prev button and prints it.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from PySide.QtCore import *
from PySide.QtGui import *
import sys
import S
import L
import O
class MainWindow():
def __init__(self, Module, initValues):
self.module = Module(initValues)
print(self.module.instruction.prev.text()) # Works! Yay!
self.module.instruction.prev.clicked.connect(self.p) # Doesn't! Boo!
self.module.instruction.next.clicked.connect(self.n) # Doesn't! Boo!
def p(self):
print("Previous pressed")
def n(self):
print("Next pressed")
class Broken():
def __init__(self, why, width, height):
"""When I put the following in main(), everything works"""
initValues = {}
if why == "S":
ui = MainWindow(S.UI, initValues)
elif why == "L":
ui = MainWindow(L.UI, initValues)
elif why == "O":
ui = MainWindow(O.UI, initValues)
def main():
why = input("S, L, O? ")
app = QApplication(sys.argv)
screen_resolution = app.desktop().screenGeometry()
width, height = screen_resolution.width(), screen_resolution.height()
broken = Broken(why, width, height) # UI shows, button clicks don't
sys.exit(app.exec_())
if __name__ == "__main__":
main()
Solution
Once again, @ekhumoro has "schooled" me, though I'll probably embarrass myself again in the future.
The problem was solved by adding parents to everything to prevent aggressive garbage collection.
Answered By - Ubuntourist
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.