R
R
railee2021-05-22 19:52:46
Python
railee, 2021-05-22 19:52:46

PyQt5. How to switch between windows by passing data?

I need to launch another from one window by passing the login variable. How it is possible to implement it?
Here is the code (stripped down):

class LogWin(QtWidgets.QMainWindow, Login):
    def __init__(self):
        super().__init__()
        self.setupUi(self)
        self.pushButton.pressed.connect(self.login)

    def error(self):
        QMessageBox.about(self, "Error", "Логин неверный.")

    def login(self):
        login = self.lineEdit.text()
        response = requests.get('http://127.0.0.1:5000/login')
        logins = response.json()['logins']
        if login in logins:
            self.hide()
            clien.start(login)
        else:
            self.error()
            self.lineEdit.clear()


class Messenger(QtWidgets.QMainWindow, Ui_MainWindow):
    def __init__(self, login):
        super().__init__()
        self.setupUi(self)
        self.label_3 = login
def start(login):
    app = QtWidgets.QApplication([])
    window = Messenger(login=login)
    window.show()
    app.exec()

reg = QtWidgets.QApplication([])
regwin = LogWin()
regwin.show()
reg.exec()

This code, after entering the correct login, is interrupted by the error: "Process finished with exit code -1073741819 (0xC0000005)", and the debugger is silent...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
railee, 2021-05-23
@railee

Solution:

class LogWin(QtWidgets.QMainWindow, Login):
    def __init__(self):
        super().__init__()
        self.setupUi(self)
        self.pushButton.pressed.connect(self.login)

    def error(self):
        QMessageBox.about(self, "Error", "Логин неверный.")

    def login(self):
        login = self.lineEdit.text()
        response = requests.get('http://127.0.0.1:5000/login')
        logins = response.json()['logins']
        if login in logins:
            self.hide()
            self.window = Messenger(login = login)
            self.window.show()
        else:
            self.error()
            self.lineEdit.clear()

reg = QtWidgets.QApplication([])
regwin = LogWin()
regwin.show()
reg.exec()

class Messenger(QtWidgets.QMainWindow, Ui_MainWindow):
    def __init__(self, login):
        super().__init__()
        self.setupUi(self)
        self.label_3.setText(login)
        self.label_3 = login

def start() is not needed

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question