我试图将争论从一个类传递到另一个类但没有成功。我阅读了一些帖子(Python: How do I pass variables between class instances or get the caller?; Python-passing variable between classes),但即使在那之后我也无法完成这项工作:
class App(QMainWindow):
def __init__(self, parent = None):
super(App,self).__init__(parent)
self.initUI()
def on_LP(self):
self.var = 'Last purchase'
self.TBView = TBWindow()
self.TBView.showMaximized()
def initUI(self):
self.setWindowTitle(self.title)
mainMenu = self.menuBar()
Historie = mainMenu.addMenu('History')
Historie.addAction('Last purchase').triggered.connect(self.on_LP)
class TBWindow(QTableView):
def __init__(self, parent = None):
super(TBWindow,self).__init__(parent)
if var == 'Last purchase':
sql = "select * from purchases where Purchase_time = (select max(Purchase_time) from purchases)"
args = []
变量var在def on_LP中创建,应该传递给TBWindow类,在那里使用它。但是,我没有把它传递到那里。有什么建议如何处理?感谢