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. Close QDialog: Not calling the on_clicked() method

Close QDialog: Not calling the on_clicked() method

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 450 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.
  • F Offline
    F Offline
    fem_dev
    wrote on last edited by
    #1

    I'm developing a Qt C++ GUI shared library.

    void Plugin::showUI() const {
        Dialog a;
    
        a.setModal(true);
        a.exec();
    }
    

    My UI have a buttom called "Save".

    void Dialog::on_save_btn_clicked()
    {
        qDebug() << "SAVE";
    }
    

    It compiles without any warnings or errors. All ok!
    The plugin UI appears ok too.

    My problem: When I click on the save button, the method above is not called! Why?

    How can I fix it?

    1 Reply Last reply
    0
    • F fem_dev

      @SGaist sorry...here is my Dialog class.

      #ifndef DIALOG_H
      #define DIALOG_H
      
      #include <QDialog>
      
      namespace Ui {
      class Dialog;
      }
      
      class Dialog : public QDialog
      {
          Q_OBJECT
      
      public:
          explicit Dialog(QWidget *parent = nullptr);
          ~Dialog();
      
          void on_save_btn_clicked();
      
      private:
          Ui::Dialog *ui;
      };
      
      #endif // DIALOG_H
      
      #include "dialog.h"
      #include "ui_dialog.h"
      
      #include <QDebug>
      
      Dialog::Dialog(QWidget *parent) :
          QDialog(parent),
          ui(new Ui::Dialog)
      {
          ui->setupUi(this);
      }
      
      Dialog::~Dialog()
      {
          delete ui;
      }
      
      void Dialog::on_save_btn_clicked()
      {
          qDebug() << "SAVE";
      }
      

      I just added this "save_btn_clicked" from the Qt Designer using: right-click -> Go To Slot -> Clicked()

      B Offline
      B Offline
      Bonnie
      wrote on last edited by Bonnie
      #4

      @fem_dev said in Close QDialog: Not calling the on_clicked() method:

      I just added this "save_btn_clicked" from the Qt Designer using: right-click -> Go To Slot -> Clicked()

      It can't be...The "save_btn_clicked" function is not even a slot!
      That's why it doesn't work...
      If you create it using designer, it should be added as a slot like this:

      private slots:
          void on_save_btn_clicked();
      

      Unless you've deleted that "private slots:" line.

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

        Hi,

        Without the code form Dialog, it's hard to guess...

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

        F 1 Reply Last reply
        0
        • SGaistS SGaist

          Hi,

          Without the code form Dialog, it's hard to guess...

          F Offline
          F Offline
          fem_dev
          wrote on last edited by
          #3

          @SGaist sorry...here is my Dialog class.

          #ifndef DIALOG_H
          #define DIALOG_H
          
          #include <QDialog>
          
          namespace Ui {
          class Dialog;
          }
          
          class Dialog : public QDialog
          {
              Q_OBJECT
          
          public:
              explicit Dialog(QWidget *parent = nullptr);
              ~Dialog();
          
              void on_save_btn_clicked();
          
          private:
              Ui::Dialog *ui;
          };
          
          #endif // DIALOG_H
          
          #include "dialog.h"
          #include "ui_dialog.h"
          
          #include <QDebug>
          
          Dialog::Dialog(QWidget *parent) :
              QDialog(parent),
              ui(new Ui::Dialog)
          {
              ui->setupUi(this);
          }
          
          Dialog::~Dialog()
          {
              delete ui;
          }
          
          void Dialog::on_save_btn_clicked()
          {
              qDebug() << "SAVE";
          }
          

          I just added this "save_btn_clicked" from the Qt Designer using: right-click -> Go To Slot -> Clicked()

          B 1 Reply Last reply
          0
          • F fem_dev

            @SGaist sorry...here is my Dialog class.

            #ifndef DIALOG_H
            #define DIALOG_H
            
            #include <QDialog>
            
            namespace Ui {
            class Dialog;
            }
            
            class Dialog : public QDialog
            {
                Q_OBJECT
            
            public:
                explicit Dialog(QWidget *parent = nullptr);
                ~Dialog();
            
                void on_save_btn_clicked();
            
            private:
                Ui::Dialog *ui;
            };
            
            #endif // DIALOG_H
            
            #include "dialog.h"
            #include "ui_dialog.h"
            
            #include <QDebug>
            
            Dialog::Dialog(QWidget *parent) :
                QDialog(parent),
                ui(new Ui::Dialog)
            {
                ui->setupUi(this);
            }
            
            Dialog::~Dialog()
            {
                delete ui;
            }
            
            void Dialog::on_save_btn_clicked()
            {
                qDebug() << "SAVE";
            }
            

            I just added this "save_btn_clicked" from the Qt Designer using: right-click -> Go To Slot -> Clicked()

            B Offline
            B Offline
            Bonnie
            wrote on last edited by Bonnie
            #4

            @fem_dev said in Close QDialog: Not calling the on_clicked() method:

            I just added this "save_btn_clicked" from the Qt Designer using: right-click -> Go To Slot -> Clicked()

            It can't be...The "save_btn_clicked" function is not even a slot!
            That's why it doesn't work...
            If you create it using designer, it should be added as a slot like this:

            private slots:
                void on_save_btn_clicked();
            

            Unless you've deleted that "private slots:" line.

            F 1 Reply Last reply
            3
            • B Bonnie

              @fem_dev said in Close QDialog: Not calling the on_clicked() method:

              I just added this "save_btn_clicked" from the Qt Designer using: right-click -> Go To Slot -> Clicked()

              It can't be...The "save_btn_clicked" function is not even a slot!
              That's why it doesn't work...
              If you create it using designer, it should be added as a slot like this:

              private slots:
                  void on_save_btn_clicked();
              

              Unless you've deleted that "private slots:" line.

              F Offline
              F Offline
              fem_dev
              wrote on last edited by
              #5

              @Bonnie said in Close QDialog: Not calling the on_clicked() method:

              Unless you've deleted that "private slots:" line.

              Perfect @Bonnie ....I've deleted this line...
              Thank you!

              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