How to get rid of changed code lingering in the moc?

  • In my main menu, I had an action set up and its accompanying code. Then I decided to change the action name on the menu to something else. I did that and took the code from the first, no-longer-needed action and gave it to the new action. Now I get this each time I run it:

    QMetaObject::connectSlotsByName: No matching signal for on_actionA_lter_triggered()

    I've tried to "Clean" the build, thinking that would cure the moc's ailment, but no dice. So what can I do to fix this? This is the ONE thing about Qt that drives me crazy.

  • Qt Champions 2018

    hi @landslyde

    you most likely still have the slot function in you code, but the signal no longer exists.

    that's what the connect error message is going to tell you.

  • I've tried taking it out. That only throws an error in the moc. I'll post this.

    Code commented out:

    //void MainWindow::on_actionA_lter_triggered()

    Error thrown in the moc:

    /home/slyde/Desktop/Qt/build-Qt_Stacked_Widget-Desktop_Qt_5_11_0_GCC_64bit-Debug/moc_mainwindow.cpp:100: error: undefined reference to `MainWindow::on_actionA_lter_triggered()'

    The error code:

    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_actionE_xit_triggered(); break;
            case 1: _t->on_actionA_lter_triggered(); break;  // throws error here
            case 2: _t->on_action_Add_triggered(); break;
            case 3: _t->on_action_Delete_triggered(); break;
            case 4: _t->on_action_View_triggered(); break;
            case 5: _t->on_action_Search_triggered(); break;
            case 6: _t->on_btnCancel_add_recipe_clicked(); break;
            case 7: _t->on_action_Edit_triggered(); break;
            default: ;

    I can comment out that line "case 1:" and I go back to getting a warning. There has to be a way for this to be cleaned out of the code. I know I'm not the first person that's ever changed his mind on the name of something.

  • Fixed it. Thank you, aha_1980.

  • Qt Champions 2018

    Hi @landslyde,

    glad you figured it out.

    Running Qmake most often helps, in very rare cases you need to delete your build folder to get the error away.

  • Actually, while I'd deleted the action code from mainwindow.cpp, I hadn't deleted its prototype in mainwindow.h. That's what the compiler was complaining about. So I deleted it in the .h and then ran Build -> Clean All. Doing that removed the reference to the deleted action in the moc file. Problem solved. Thanks again for your help.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.