简体   繁体   中英

pyside second qt gui doesn't show up

I have a Qapplication in my python script that gives a logingui to my chat server. When the login is complete I want to call upon my chat gui. To achieve this I've used the following code:

app = QApplication(sys.argv)
form = LoginWindow()
form.show()
app.exec_()
#login done
form = ChatWindow()
form.show()
app.exec_()

This worked when I fired it up with an "empty" gui of the chat. So only the necessary things in it for it to boot up. However when I start connecting signals and stuff the second window just doesn't show up anymore. The console prints a statement from the beginning of the init but after that it falls silent and no gui is present.

Does anyone know how I can fix this weird problem? How is switching a form supposed to be done?

The login window should be a subclass of QDialog , so that it can be run separately from the main application. A QDialog has its own event loop, and provides a return code that can be used to check which action was taken by the user.

So, given this, your code would become:

app = QApplication(sys.argv)
dialog = LoginWindow()
if dialog.exec_() == QDialog.Accepted:
    window = ChatWindow()
    window.show()
    app.exec_()
else:
    print('Login cancelled')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM