Jun-19-2019, 07:00 PM
Hi
I got a problem with calling a funtion from another class. I have searched a bit but i can't find a good solution to my problem. Can any one help me? All my code need to do is call prot function in class Form from the while loop in myClassA.
I got a problem with calling a funtion from another class. I have searched a bit but i can't find a good solution to my problem. Can any one help me? All my code need to do is call prot function in class Form from the while loop in myClassA.
import sys import time from PySide2.QtSql import QSqlQueryModel,QSqlDatabase,QSqlQuery from PySide2.QtUiTools import QUiLoader from PySide2.QtWidgets import QApplication, QPushButton, QLineEdit, QTableView, QTableWidget from PySide2.QtCore import QFile, QObject from threading import Thread class Form(QObject): def __init__(self, ui_file, parent=None): super(Form, self).__init__(parent) ui_file = QFile(ui_file) ui_file.open(QFile.ReadOnly) loader = QUiLoader() self.window = loader.load(ui_file) ui_file.close() self.line = self.window.findChild(QLineEdit, 'lineEdit') btn = self.window.findChild(QPushButton, 'pushButton') btn2 = self.window.findChild(QPushButton, 'pushButton_2') self.tableView = self.window.findChild(QTableView, 'tableView') self.tableWidget = self.window.findChild(QTableWidget, 'tableWidget') self.db = QSqlDatabase.addDatabase("QSQLITE") self.db.setDatabaseName("database.db") self.db.open() self.projectModel = QSqlQueryModel() self.projectModel.setQuery("select * from tider",self.db) self.tableView.setModel(self.projectModel) btn.clicked.connect(self.ok_handler) btn2.clicked.connect(self.prot) self.window.show() myClassA() def ok_handler(self): language = 'None' if not self.line.text() else self.line.text() print('Favorite language: {}'.format(language)) def prot(self): self.projectModel = QSqlQueryModel() self.projectModel.setQuery("select * from tider",self.db) self.tableView.setModel(self.projectModel) class myClassA(Thread): def __init__(self): Thread.__init__(self) self.daemon = True self.start() def run(self): while True: print ('A') time.sleep(1) if __name__ == '__main__': app = QApplication(sys.argv) form = Form('mainwindow.ui') sys.exit(app.exec_())