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. QMessage box signal and slot

QMessage box signal and slot

Scheduled Pinned Locked Moved General and Desktop
9 Posts 3 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.
  • L Offline
    L Offline
    lash
    wrote on last edited by
    #1

    is there any way to connect QMessageBox ok button clicked signal to a slot in another class

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      If you are not using the static methods, then yes it is

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • L Offline
        L Offline
        lash
        wrote on last edited by lash
        #3

        hi and thank you,I wanted to call a slot in another class when ever QMessageBox Yes Button is clicked and I am not using static methods.Icouldnt figure out how

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Use QMessageBox::button to retrieve the correct button and connect it accordingly

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • L Offline
            L Offline
            lash
            wrote on last edited by
            #5

            I tried like this but didnt work
            connect(anotherclass->deleteMsgBox.button(QMessageBox::Yes),SIGNAL(clicked()),this,SLOT(repaint()));

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mcosta
              wrote on last edited by mcosta
              #6

              Hi and welcome to devnet,

              In that case I suggest to use signal forwarding

              1. create a SIGNAL in the anotherClass
              2. connect the message box signal to that signal
              3. connect the first signal to repaint
              // AnotherClass.h
              class QMessageBox;
              
              class AnotherClass 
              {
              Q_SIGNALS:
                  void messageBoxOkClicked();
              
              private:
                  QMessageBox *deleteMsgBox;
              };
              
              //AnotherClass.cpp
              AnotherClass::AnotherClass() 
              {
                  deleteMsgBox = new QMessageBox(this);
              
                  connect(deleteMsgBox.button(QMessageBox::Yes), SIGNAL(clicked()), this, SIGNAL(messageBoxOkClicked()));
              }
              
              //Widget.cpp
              connect (anotherClass, SIGNAL(messageBoxOkClicked()), this, SLOY(repaint()));
              

              Once your problem is solved don't forget to:

              • Mark the thread as SOLVED using the Topic Tool menu
              • Vote up the answer(s) that helped you to solve the issue

              You can embed images using (http://imgur.com/) or (http://postimage.org/)

              1 Reply Last reply
              0
              • L Offline
                L Offline
                lash
                wrote on last edited by lash
                #7

                I tried this but it didnt work ,How can I connect two SIGNALS

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  mcosta
                  wrote on last edited by
                  #8

                  you can connect 2 signals how I wrote.

                  can you post your code??

                  Once your problem is solved don't forget to:

                  • Mark the thread as SOLVED using the Topic Tool menu
                  • Vote up the answer(s) that helped you to solve the issue

                  You can embed images using (http://imgur.com/) or (http://postimage.org/)

                  1 Reply Last reply
                  0
                  • L Offline
                    L Offline
                    lash
                    wrote on last edited by
                    #9

                    anotherclass.h

                    QMessageBox deleteMsgBox;

                    anotherclass.cpp:QGraphicsRectItem

                    anotherclass::delete()
                    {
                    deleteMsgBox.setText("Deleting state...");
                    deleteMsgBox.setInformativeText("Are you sure you want to delete this state?");
                    deleteMsgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
                    deleteMsgBox.setDefaultButton(QMessageBox::No);

                    ret = deleteMsgBox.exec();
                    if(ret == QMessageBox::Yes){
                    .................
                    }
                    

                    }
                    mainclass.cpp{

                    mainclass::make()
                    {
                    connect(anotherclass->deleteMsgBox.button(QMessageBox::Yes),SIGNAL(clicked()),this,SLOT(repaint()));
                    }
                    mainclass::repaintAll()
                    {
                    ..............
                    }
                    }

                    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