[Solved] Don't close Dialog on clicking OK button of QMessageBox



  • I have called QMessageBox() like this:
    @
    class Main(QDialog):
    def init(self):
    self.view = QUiLoader().load("app.ui", self)
    self.viewshow()
    .
    .
    functionA():
    try:
    ....
    except:
    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 ?


  • Moderators

    Hi, welcome to devnet.

    First - you shouldn't call it like this. critical() is a static method. You can just call it like that (without an instance of QMessageBox):
    @
    QMessageBox::critical(self, "Error", "System Failure");
    @
    Second - the only way this can close anything but the message box itself is if it's the first and last window of your app. If it's not the case then you've got some error in your code and to help you we need to see more. Where and how you call it. What are the close conditions for the dialog etc.



  • I haven't created an instance of QMessageBox(). Actually i have written above code in python.

    [quote author="Chris Kawa" date="1418205926"]Hi, welcome to devnet.

    First - you shouldn't call it like this. critical() is a static method. You can just call it like that (without an instance of QMessageBox):
    @
    QMessageBox::critical(self, "Error", "System Failure");
    @
    Second - the only way this can close anything but the message box itself is if it's the first and last window of your app. If it's not the case then you've got some error in your code and to help you we need to see more. Where and how you call it. What are the close conditions for the dialog etc.[/quote]


  • Moderators

    Huh, python. That's an information you might have wanted to share ;)

    Still. I would expect it to behave similarly so we still need to see the call site.



  • reply to Second part:
    dialog is my first window


  • Moderators

    Then you're doing something else wrong. It's really hard to guess like that. Your description is more or less "I have a problem. What's wrong?".



  • Here QMessageBox should be used like this:
    @
    QMessageBox.critical(self, "Error", "System Failure")@


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.