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. What does QObject::connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); do in following code
Forum Updated to NodeBB v4.3 + New Features

What does QObject::connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); do in following code

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 5.4k 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.
  • Q Offline
    Q Offline
    Qt Enthusiast
    wrote on 5 Dec 2016, 04:37 last edited by
    #1

    QDialogButtonBox* buttonBox = new QDialogButtonBox();
    buttonBox->setStandardButtons(QDialogButtonBox::Apply | QDialogButtonBox::Close);
    QPushButton* applyButton = buttonBox->button(QDialogButtonBox::Apply);
    QObject::connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));

    1 Reply Last reply
    0
    • J Offline
      J Offline
      joeQ
      wrote on 5 Dec 2016, 05:09 last edited by joeQ 12 May 2016, 05:14
      #2

      Hi, friend. Welcome.
      The Qt manual said:

      [signal] void QDialogButtonBox::accepted()
      This signal is emitted when a button inside the button box is clicked, as long as it was defined with the AcceptRole or YesRole.

      QDialogButtonBox include more than one button. If there is a AcceptRole button clicked and the signal will be emitted. From the signal, we can know AcceptRole button is clicked in QDialogButtonBox.

      eg:

      #include "widget.h"
      #include "ui_widget.h"
      
      #include <QDialogButtonBox>
      #include <QDebug>
      
      Widget::Widget(QWidget *parent) :
          QWidget(parent),
          ui(new Ui::Widget)
      {
          ui->setupUi(this);
      
          QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Save | QDialogButtonBox::Cancel, this);
          ///< Ok and Save is AcceptRole
          connect(buttonBox, &QDialogButtonBox::accepted, this, [=](){ qDebug("ok or save");     });
          connect(buttonBox, &QDialogButtonBox::rejected, this, [=](){ qDebug("cancel"); });
      }
      
      Widget::~Widget()
      {
          delete ui;
      }
      
      

      Add the button roles: enum QDialogButtonBox::StandardButton
      eg:

      QDialogButtonBox::Ok An "OK" button defined with the AcceptRole.
      QDialogButtonBox::Open An "Open" button defined with the AcceptRole.
      QDialogButtonBox::Save A "Save" button defined with the AcceptRole.
      QDialogButtonBox::Cancel A "Cancel" button defined with the RejectRole.
      QDialogButtonBox::Close A "Close" button defined with the RejectRole.

      Just do it!

      1 Reply Last reply
      4

      1/2

      5 Dec 2016, 04:37

      • Login

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