Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] Don't close Dialog on clicking OK button of QMessageBox

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

Scheduled Pinned Locked Moved General and Desktop
7 Posts 2 Posters 2.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Patrick2391
    wrote on last edited by
    #1

    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 ?

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • P Offline
        P Offline
        Patrick2391
        wrote on last edited by
        #3

        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]

        1 Reply Last reply
        0
        • Chris KawaC Offline
          Chris KawaC Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • P Offline
            P Offline
            Patrick2391
            wrote on last edited by
            #5

            reply to Second part:
            dialog is my first window

            1 Reply Last reply
            0
            • Chris KawaC Offline
              Chris KawaC Offline
              Chris Kawa
              Lifetime Qt Champion
              wrote on last edited by
              #6

              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?".

              1 Reply Last reply
              0
              • P Offline
                P Offline
                Patrick2391
                wrote on last edited by
                #7

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

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved