I wanted to create a small dialog that using buttons we can add some numbers.
First I designed a form by Qt Designer using Dialog Without Buttons template like this:

1.jpg

Then I wrote a calculator.h file like this:


Qt Code:
  1. #ifndef CALCULATOR_H
  2. #define CALCULATOR_H
  3.  
  4. #include<QDialog>
  5. #include "ui_Calculator.h"
  6.  
  7. class Calculator : public QDialog, public Ui::Calculator
  8. {
  9. Q_OBJECT
  10.  
  11. public:
  12. Calculator(QWidget* parent = 0);
  13.  
  14. private slots:
  15. void myslot();
  16. };
  17.  
  18. #endif // CALCULATOR_H
To copy to clipboard, switch view to plain text mode 


Then, a calculator.cpp this way:


Qt Code:
  1. #include <QtWidgets>
  2. #include "calculator.h"
  3.  
  4. Calculator::Calculator(QWidget *parent)
  5. :QDialog(parent)
  6. {
  7. setupUi(this);
  8.  
  9. connect(oneButton,SIGNAL(clicked(bool)), lineEdit, SLOT(myslot()));
  10. }
  11.  
  12. void Calculator::myslot(){
  13. lineEdit -> setText("1");
  14. }
To copy to clipboard, switch view to plain text mode 


And finally the main.cpp this way:

Qt Code:
  1. #include <QApplication>
  2. #include <QDialog>
  3.  
  4. #include "ui_Calculator.h"
  5.  
  6. int main(int argc, char* argv[])
  7. {
  8. QApplication app(argc, argv);
  9.  
  10. Ui::Calculator ui;
  11. QDialog* dialog = new QDialog;
  12. ui.setupUi(dialog);
  13. dialog -> show();
  14.  
  15. return app.exec();
  16. }
To copy to clipboard, switch view to plain text mode 

Now the code runs without any error but not as expected! That is when I click on '1' button nothing will be printed out onto the lineEdit.
Why please and how to solve it?