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. buttonClicked() for button on QMessageBox
Qt 6.11 is out! See what's new in the release blog

buttonClicked() for button on QMessageBox

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 1.3k Views 1 Watching
  • 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.
  • T Offline
    T Offline
    Tejaswini_14
    wrote on last edited by
    #1

    I am trying to call "removeDuplicate()" method on clicking 'Ok' button of QMessageBox. But when I click the button the method doesn't execute. What should I do?
    Here is code snippet :

    def removeDuplicate(self):
            curItem = self.listWidget_2.currentItem()
            self.listWidget_2.takeItem(curItem)
    
    def error_popup(self):
            msg=QtWidgets.QMessageBox()
            msg.setText("You can't select more than one wicket-keeper.")
            msg.setWindowTitle(" ")
            msg.setIcon(QtWidgets.QMessageBox.Critical)
            x = msg.exec_()
            msg.setStandardButtons(QtWidgets.QMessageBox.Ok)
            msg.buttonClicked.connect(self.removeDuplicate)
    
    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #5

      Hi
      All setup including connect must come before
      x = msg.exec_()

      T 1 Reply Last reply
      2
      • Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #2

        You connect the slot after you executed / shown the message box - so what do you expect?

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        T 1 Reply Last reply
        4
        • Christian EhrlicherC Christian Ehrlicher

          You connect the slot after you executed / shown the message box - so what do you expect?

          T Offline
          T Offline
          Tejaswini_14
          wrote on last edited by
          #3

          @Christian-Ehrlicher I want the "removeDuplicate" method to be executed when I will click on the 'Ok' button. By this method I want to remove item from one QListWidget and add it to another one.

          1 Reply Last reply
          0
          • Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #4

            @Tejaswini_14 said in buttonClicked() for button on QMessageBox:

            I want the "removeDuplicate" method to be executed when I will click on the 'Ok' button.

            fine but this doesn't answer my question - when you first execute the dialog and only afterwards connect the signal once the dialog is already closed - how should it work?

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            1 Reply Last reply
            2
            • mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #5

              Hi
              All setup including connect must come before
              x = msg.exec_()

              T 1 Reply Last reply
              2
              • mrjjM mrjj

                Hi
                All setup including connect must come before
                x = msg.exec_()

                T Offline
                T Offline
                Tejaswini_14
                wrote on last edited by
                #6

                @mrjj Thanks a lot Sir!

                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