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. How can I enable the QDialogButtonBox
Forum Updated to NodeBB v4.3 + New Features

How can I enable the QDialogButtonBox

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 3.1k 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.
  • N Offline
    N Offline
    Neutrox
    wrote on last edited by
    #1

    Hello!
    I am creating a GUI and I inserted in it a QDialogButtonBox in Designer.
    I seek a function that enables the OK button (which should close the screen and save changes)
    and a Cancel button (which should close the program and not save changes).

    1 Reply Last reply
    0
    • N Offline
      N Offline
      Neutrox
      wrote on last edited by
      #2

      someone help me?

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

        Hi,

        Select the button box, go to the property editor and scroll down until you find standardButtons, there you can select which one you want

        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
        • N Offline
          N Offline
          Neutrox
          wrote on last edited by
          #4

          But in this property only selects a button name and not a function to cancel and not save, for example.

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andreyc
            wrote on last edited by
            #5

            From the "QDialogButtonBox help":http://qt-project.org/doc/qt-5/qdialogbuttonbox.html#details

            "When a button is clicked in the button box, the clicked() signal is emitted for the actual button is that is pressed. For convenience, if the button has an AcceptRole, RejectRole, or HelpRole, the accepted(), rejected(), or helpRequested() signals are emitted respectively."

            You need to connect the signals, at least "clicked()":http://qt-project.org/doc/qt-5/qdialogbuttonbox.html#clicked to the slots in your class and process the buttons.

            1 Reply Last reply
            0
            • N Offline
              N Offline
              Neutrox
              wrote on last edited by
              #6

              I created the signal:
              @MainWindow::MainWindow(QWidget *parent) :
              QMainWindow(parent),
              ui(new Ui::MainWindow)

              {
              ui->setupUi(this);

              connect(ui->buttonBox,SIGNAL(clicked()),this,on_buttonBox_accepted());
              connect(ui->buttonBox,SIGNAL(clicked()),this,on_buttonBox_rejected());
              }@

              and the functions:
              @void MainWindow::on_buttonBox_accepted()
              {

              }

              void MainWindow::on_buttonBox_rejected()
              {

              }
              @

              But has an error in connect:
              error: invalid use of void expression.

              How can I solve that?

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andreyc
                wrote on last edited by
                #7

                Two things.

                If you create a slot from designer "Goto slot"/accepted, rejected then you don't need to connect them manually. So just delete two connect() lines and it should work.

                If you prefer to connect manually then you connect call is not correct.

                It should look like this
                @
                connect(ui->buttonBox, SIGNAL(clicked(QAbstractButton*)),
                this, SLOT(buttonClicked(QAbstractButton*)));
                @

                1 Reply Last reply
                0
                • N Offline
                  N Offline
                  Neutrox
                  wrote on last edited by
                  #8

                  One way I found to solve my problem was to put in my function @ void MainWindow::on_buttonBox_accepted()
                  @ the execution to write in my text file and then used the @qApp->quit()@
                  And @ void MainWindow::on_buttonBox_rejected()
                  @ I put only the @qApp->quit()@ to close and not execute any writing in my file.

                  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