1

I have called QMessageBox() like this:

class Main(QDialog):
    def __init__(self):
        self.view = QUiLoader().load("app.ui", self)
        self.view.show()
        self.functionA()
    ....
    functionA():
        try:
            ....
        except Exception:
            QMessageBox.critical(self, "Error", "System Failure")

def main():
    app = QApplication(sys.argv)
    a = Main()
    sys.exit(app.exec_())

if __name__ == "__main__"
    main()

When i click OK button of Message box it also closes my Dialog. How to avoid this ?

4

2 回答 2

1

Your code example (slightly altered to make it run) works for me:

from PySide.QtGui import *

class Main(QDialog):
    def __init__(self):
        super().__init__()
        self.show()
        self.functionA()

    def functionA(self):
        try:
            raise Exception()
        except Exception:
            QMessageBox.critical(self, "Error", "System Failure")

app = QApplication([])
a = Main()
app.exec_()

You can press OK on the message box and the dialog will not be closed. You are probably doing something else too that causes the closing of the dialog.

于 2014-12-15T09:52:11.850 回答
1

Use QMessageBox like this:

QMessageBox.critical(self.view, "Error", "System Failure")
于 2015-01-01T09:19:06.523 回答