Skip to content Skip to sidebar Skip to footer

Pyqt Application Freezes If Dialog Rejected

I have a small application, that requires login before it starts. But if user rejects login(press cancel button), application won't close, it's just freeze. Here is the simplified

Solution 1:

This happens because PySide has not processed any of it's events.

app.exec_()

This starts the main event loop that continually processes every GUI interaction. This should be called before you execute any GUI code, so the events can be processed correctly from the event Queue.

The QDialog.exec_() is a blocking operation preventing the code from continuing until it gets a response.

If you want to see the dialog items then you may be able to get around this.

QtGui.QApplication.processEvents()

This processes all of the events in the event Queue, so you would probably have to keep calling this method.

Also after you initialize your main window you will have to show the main window.

Solution 2:

I find a way to avoid this bug:

I've changed main function:

def main():
    app = QtWidgets.QApplication([])
    if LoginWindow().exec_() == QtWidgets.QDialog.Accepted:
        m = MainWindow()
        sys.exit(app.exec_())

And it works normal, but is still can't understand, what was the root cause of the problem

Post a Comment for "Pyqt Application Freezes If Dialog Rejected"