3
votes

I have created a Qt Widgets Project using Qt Creator wizard(Windows 7, MinGW, 64 bit). Then I have added a push button pbClick to the main window (with mainwindow.ui). Now right click on the UI pushButton and clicked on Go to Slot. This created the following function:

void MainWindow::on_pbClick_clicked()
{
    this->close();//added by me.
}

in the mainwindow.cpp file.

The program is working fine.

Now I deleted the push button from the user interface by right clicking delete.

And I deleted the above function MainWindow::on_pbClick_clicked() manually.

If I try to run the program, an error message comes.

C:\QtProjects\QtWidgets\build-QtWidgetsTest-Desktop_Qt_5_3_MinGW_32bit-Debug\debug\moc_mainwindow.cpp:67: error: undefined reference to `MainWindow::on_pbClick_clicked()

The error is coming in the following function

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_pbClick_clicked(); break;
        default: ;
        }
    }
    Q_UNUSED(_a);
}

defined in the moc_mainwindow.cpp

How to completely remove the button along with its click event(slot) .

1

1 Answers

6
votes

Ensure that you've removed the reference to the on_pbClick_clicked() function in the header of MainWindow.h as well as its implementation MainWindow.cpp.

If no other references remain, run qmake, which can be found under the "Build" menu.