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. Connect MessageBox buttonClicked() signal does not work

Connect MessageBox buttonClicked() signal does not work

Scheduled Pinned Locked Moved Solved General and Desktop
messagebox
5 Posts 3 Posters 1.4k 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.
  • D Offline
    D Offline
    dalishi
    wrote on 18 Jun 2019, 06:01 last edited by dalishi
    #1

    Hi

    In MyClass, i have a messageBox pointer member variable and in MyClass constructor:

    msgBox = new QMessageBox(QMessageBox::Information, tr("Request"),
                                            "Waiting ...", QMessageBox::Cancel, this);
    

    when it is needed to open the message box:

    msgBox->open(this, SLOT(waitReplyCancelled(QAbstractButton*))); // connect MessageBox::buttonClicked() to slot
    
    

    I need the control to return immediately back to the main loop so I did not use exec(), etc. It works just fine. When I clicked the Cancel button, the message box closed and the following slot was called. No problem.

    void MyClass::waitReplyCancelled(QAbstractButton* buttonClicked) {
        qDebug() << "I'm waitReplyCancelled(QAbstractButton*)";
    }
    

    Okay now I want to manually connect the slot as I don't want every time the message box is opened it need to connect the signal again like in open(). So I use show() instead and try to connect to the signal myself. So in MyClass constructor:

    msgBox = new QMessageBox(QMessageBox::Information, tr("Request"),
                                            "Waiting ...", QMessageBox::Cancel, this);
    connect(msgBox, SIGNAL(buttonClicked(QAbstractButton *button)), this, SLOT(waitReplyCancelled(QAbstractButton *button)));
    msgBox->setModal(true);
    

    When the message box is needed, I just show() the message box:

    msgBox->show();
    

    Unfortunately, this way does not work. When I clicked the Cancel button, the message box closed but the slot was not called.

    Anyone can help me?

    J J 2 Replies Last reply 18 Jun 2019, 06:04
    0
    • D dalishi
      18 Jun 2019, 06:01

      Hi

      In MyClass, i have a messageBox pointer member variable and in MyClass constructor:

      msgBox = new QMessageBox(QMessageBox::Information, tr("Request"),
                                              "Waiting ...", QMessageBox::Cancel, this);
      

      when it is needed to open the message box:

      msgBox->open(this, SLOT(waitReplyCancelled(QAbstractButton*))); // connect MessageBox::buttonClicked() to slot
      
      

      I need the control to return immediately back to the main loop so I did not use exec(), etc. It works just fine. When I clicked the Cancel button, the message box closed and the following slot was called. No problem.

      void MyClass::waitReplyCancelled(QAbstractButton* buttonClicked) {
          qDebug() << "I'm waitReplyCancelled(QAbstractButton*)";
      }
      

      Okay now I want to manually connect the slot as I don't want every time the message box is opened it need to connect the signal again like in open(). So I use show() instead and try to connect to the signal myself. So in MyClass constructor:

      msgBox = new QMessageBox(QMessageBox::Information, tr("Request"),
                                              "Waiting ...", QMessageBox::Cancel, this);
      connect(msgBox, SIGNAL(buttonClicked(QAbstractButton *button)), this, SLOT(waitReplyCancelled(QAbstractButton *button)));
      msgBox->setModal(true);
      

      When the message box is needed, I just show() the message box:

      msgBox->show();
      

      Unfortunately, this way does not work. When I clicked the Cancel button, the message box closed but the slot was not called.

      Anyone can help me?

      J Offline
      J Offline
      J.Hilk
      Moderators
      wrote on 18 Jun 2019, 06:04 last edited by
      #2

      @dalishi said in Connect MessageBox buttonClicked() signal does not work:

      connect(msgBox, SIGNAL(buttonClicked(QAbstractButton *button)), this, SLOT(waitReplyCancelled(QAbstractButton *button)));

      That's not a valid connect syntax, probably the problem.


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      D 1 Reply Last reply 18 Jun 2019, 06:19
      2
      • D dalishi
        18 Jun 2019, 06:01

        Hi

        In MyClass, i have a messageBox pointer member variable and in MyClass constructor:

        msgBox = new QMessageBox(QMessageBox::Information, tr("Request"),
                                                "Waiting ...", QMessageBox::Cancel, this);
        

        when it is needed to open the message box:

        msgBox->open(this, SLOT(waitReplyCancelled(QAbstractButton*))); // connect MessageBox::buttonClicked() to slot
        
        

        I need the control to return immediately back to the main loop so I did not use exec(), etc. It works just fine. When I clicked the Cancel button, the message box closed and the following slot was called. No problem.

        void MyClass::waitReplyCancelled(QAbstractButton* buttonClicked) {
            qDebug() << "I'm waitReplyCancelled(QAbstractButton*)";
        }
        

        Okay now I want to manually connect the slot as I don't want every time the message box is opened it need to connect the signal again like in open(). So I use show() instead and try to connect to the signal myself. So in MyClass constructor:

        msgBox = new QMessageBox(QMessageBox::Information, tr("Request"),
                                                "Waiting ...", QMessageBox::Cancel, this);
        connect(msgBox, SIGNAL(buttonClicked(QAbstractButton *button)), this, SLOT(waitReplyCancelled(QAbstractButton *button)));
        msgBox->setModal(true);
        

        When the message box is needed, I just show() the message box:

        msgBox->show();
        

        Unfortunately, this way does not work. When I clicked the Cancel button, the message box closed but the slot was not called.

        Anyone can help me?

        J Offline
        J Offline
        jsulm
        Lifetime Qt Champion
        wrote on 18 Jun 2019, 06:18 last edited by
        #3

        @dalishi Please check the application output - there is probably a warning saying that the connect() did not work.

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        D 1 Reply Last reply 18 Jun 2019, 06:20
        1
        • J J.Hilk
          18 Jun 2019, 06:04

          @dalishi said in Connect MessageBox buttonClicked() signal does not work:

          connect(msgBox, SIGNAL(buttonClicked(QAbstractButton *button)), this, SLOT(waitReplyCancelled(QAbstractButton *button)));

          That's not a valid connect syntax, probably the problem.

          D Offline
          D Offline
          dalishi
          wrote on 18 Jun 2019, 06:19 last edited by
          #4

          @J.Hilk Thanks. The following works without parameter names.

          connect(msgBox, SIGNAL(buttonClicked(QAbstractButton *)), this, SLOT(waitReplyCancelled(QAbstractButton *)));
          
          1 Reply Last reply
          0
          • J jsulm
            18 Jun 2019, 06:18

            @dalishi Please check the application output - there is probably a warning saying that the connect() did not work.

            D Offline
            D Offline
            dalishi
            wrote on 18 Jun 2019, 06:20 last edited by
            #5

            @jsulm Hi Thanks. I must be fool to ignore that warning....

            1 Reply Last reply
            0

            1/5

            18 Jun 2019, 06:01

            • Login

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