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. Using MessageBox buttonclicked signal

Using MessageBox buttonclicked signal

Scheduled Pinned Locked Moved Solved General and Desktop
qmessageboxsignal&slot
6 Posts 4 Posters 5.0k 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.
  • G Offline
    G Offline
    gabor53
    wrote on 22 Jul 2016, 03:56 last edited by
    #1

    Hi,
    I want to use the signal emitted by a messageBox to close a QDialog.

    I have the following code:

     QMessageBox::information (this, tr("Confirmation"), tr("<b><font size = '16' color = 'green'>The Friend was added to the database."));
     connect(QMessageBox,SIGNAL(buttonClicked(Ok)),this,SLOT(reject()));
    

    I get the following error message:
    C:\Programming\Projects\Folkfriends_1\additem.cpp:82: error: expected primary-expression before ',' token
    connect(QMessageBox,SIGNAL(buttonClicked(Ok)),this,SLOT(reject()));
    ^
    Please help me to figure out what's wrong.
    Thank you.

    1 Reply Last reply
    0
    • J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 22 Jul 2016, 04:15 last edited by
      #2

      Signals/slots don't work this way. You can only connect signals/slots using instances not just classes like you're trying. You have to instantiate QMessageBox:

      QMessageBox msgBox(this, tr("Confirmation"), tr("<b><font size = '16' color = 'green'>The Friend was added to the database."));
      // What is Ok in your example?
       connect(msgBox,SIGNAL(buttonClicked()),this,SLOT(reject()));
      msg.exec();
      

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

      1 Reply Last reply
      1
      • G Offline
        G Offline
        gabor53
        wrote on 23 Jul 2016, 03:43 last edited by
        #3

        Thank you.
        I tried this way:

        connect(&msgBox, SIGNAL(buttonClicked()),this,SLOT(reject()));
        

        and I got the following error message:
        take the address of the argument with &

        So I changed it for this:

        connect(&msgBox, SIGNAL(buttonClicked()),this,SLOT(reject()));
        

        This way there is no error message, but it doesn't do anything. Please help me to figure what else to add. Thank you.

        M 1 Reply Last reply 23 Jul 2016, 07:57
        0
        • G gabor53
          23 Jul 2016, 03:43

          Thank you.
          I tried this way:

          connect(&msgBox, SIGNAL(buttonClicked()),this,SLOT(reject()));
          

          and I got the following error message:
          take the address of the argument with &

          So I changed it for this:

          connect(&msgBox, SIGNAL(buttonClicked()),this,SLOT(reject()));
          

          This way there is no error message, but it doesn't do anything. Please help me to figure what else to add. Thank you.

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 23 Jul 2016, 07:57 last edited by mrjj
          #4

          @gabor53
          hi
          is it not
          void QMessageBox::buttonClicked(QAbstractButton * button)

          so try

          qDebug() << connect(&msgBox, SIGNAL(buttonClicked(QAbstractButton *)),this,SLOT(MYreject(QAbstractButton *)));

          void thedialog::Myreject(QAbstractButton *) {
          reject();
          }

          1 Reply Last reply
          1
          • C Offline
            C Offline
            Chris Kawa
            Lifetime Qt Champion
            wrote on 23 Jul 2016, 09:41 last edited by Chris Kawa
            #5

            This is a very contrived way of using a message box.
            The way it's meant to be used is something like:

            //taken out just to shorten the lines
            QString title = tr("Confirmation");
            QString msg = tr("<b><font size = '16' color = 'green'>The Friend was added to the database.");
            
            if (QMessageBox::information (this, title, msg) == QMessageBox::Ok)
               reject();
            

            ...although it's a little weird that you call reject() when user confirmed something.

            1 Reply Last reply
            5
            • G Offline
              G Offline
              gabor53
              wrote on 25 Jul 2016, 16:31 last edited by
              #6

              Thank you.

              1 Reply Last reply
              0

              1/6

              22 Jul 2016, 03:56

              • Login

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