I am new to Qt. I am trying to implement a really simple calculator program. Just trying to place the button, and when it is clicked, I want it to print "Hello, World!" to the next line Edit. It works fine when I have only one button, but when I add a second, it does not compile. And since I am coding a calculator, I need these buttons.
Here are the errors:
C:\Users\user\Desktop\Calc\build-Calc-Desktop_Qt_5_3_0_MinGW_32bit-Debug\debug\moc_mainwindow.o:-1: In function `ZN10MainWindow18qt_static_metacallEP7QObjectN11QMetaObject4CallEiPPv': C:\Users\user\Desktop\Calc\build-Calc-Desktop_Qt_5_3_0_MinGW_32bit-Debug\debug\moc_mainwindow.cpp:75: error: undefined reference to `MainWindow::on_pushButton_clicked()' C:\Users\user\Desktop\Calc\build-Calc-Desktop_Qt_5_3_0_MinGW_32bit-Debug\debug\moc_mainwindow.cpp:76: error: undefined reference to `MainWindow::on_pushButton_2_clicked()'
here is the MainWindow method:
void MainWindow::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a) { if (_c == QMetaObject::InvokeMetaMethod) { MainWindow *_t = static_cast<MainWindow *>(_o); switch (_id) { case 0: _t->on_pushButton_clicked(); break; case 1: _t->on_pushButton_2_clicked(); break; case 2: _t->on_pushButton_11_clicked(); break; default: ; } } Q_UNUSED(_a); }
and this is how I make the connection:
#include "mainwindow.h" #include "ui_mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); } MainWindow::~MainWindow() { delete ui; }
Does anyone know how to fix this? Thank you for your time.
source share