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. Button Cancel on Dialog not working
Forum Updated to NodeBB v4.3 + New Features

Button Cancel on Dialog not working

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 5.2k 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.
  • P Offline
    P Offline
    phamvanan
    wrote on 12 Jul 2013, 09:29 last edited by
    #1

    Hi all,
    I created a Dialog, i add a button Cancel in ButtonBox but it's not working as X symbol in tittle Dialog.
    @this->ui->buttonBox->addButton("CANCEL",QDialogButtonBox::RejectRole);@
    I want when click on X symbol in tittle of the Dialog or Cancel button then it closed.
    Please tell me a reason and resolve it.
    Thanks.

    -PVA-

    1 Reply Last reply
    0
    • J Offline
      J Offline
      Jeroentjehome
      wrote on 12 Jul 2013, 09:44 last edited by
      #2

      The x in your window will do a quit on your dialog. When you use the Cancel button set to reject it will do a close on your dialog and set the Reject code as return value, but in both cases it should close.
      What doesn't work? Your post is a bit inconclusive.

      Greetz, Jeroen

      1 Reply Last reply
      0
      • P Offline
        P Offline
        phamvanan
        wrote on 12 Jul 2013, 09:48 last edited by
        #3

        my example:
        dialog.h
        @#ifndef DIALOG_H
        #define DIALOG_H

        #include <QDialog>

        namespace Ui {
        class Dialog;
        }

        class Dialog : public QDialog
        {
        Q_OBJECT

        public:
        explicit Dialog(QWidget *parent = 0);
        ~Dialog();
        public slots:
        void reject();
        void accept();
        private:
        Ui::Dialog *ui;
        };

        #endif // DIALOG_H
        @
        dialog.cpp
        @#include "dialog.h"
        #include "ui_dialog.h"

        Dialog::Dialog(QWidget *parent) :
        QDialog(parent),
        ui(new Ui::Dialog)
        {
        ui->setupUi(this);
        this->ui->buttonBox->addButton("CANCEL",QDialogButtonBox.RejectRole);
        }

        Dialog::~Dialog()
        {
        delete ui;
        }
        void Dialog::reject(){
        QApplication::quit();
        }
        void Dialog::accept(){

        }
        @
        When i click Cancel button, Dialog not closed as expect.

        -PVA-

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 12 Jul 2013, 10:11 last edited by
          #4

          Hi,

          AFAICS your slots are not connected

          And it should rather be

          @this->ui->buttonBox->addButton("CANCEL", QDialogButtonBox::RejectRole);@

          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
          • P Offline
            P Offline
            phamvanan
            wrote on 12 Jul 2013, 10:23 last edited by
            #5

            I try to:
            @connect(this,SIGNAL(rejected()),this,SLOT(close()));@
            but it's not closed.

            -PVA-

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 12 Jul 2013, 10:31 last edited by
              #6

              The signal is not emitted like you think it is.

              You have to connect the QDialogButtonBox accepted/rejected signals to your dialog slots accept/reject slots. Close is not a good name since it's a non virtual slot of QWidget and there is already a pair of virtual slots named accept and reject for that.

              Have a look at the "QDialog documentation":http://qt-project.org/doc/qt-4.8/qdialog.html

              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

              1/6

              12 Jul 2013, 09:29

              • 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