Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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.


  • Lifetime Qt Champion

    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);
            Q_UNUSED(_t)
            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: ;
            }
        }
        Q_UNUSED(_a);
    }
    

    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.


  • Lifetime Qt Champion

    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.



  • Same thing here. Once you changed the object name for a button (or other widget), you need to comment out the deprecated slot function in the header file of the class that holds the ui form.
    The moc_mainwindow.cpp in the build folder, however, will be updated by itself, so no need to worry about that.



  • I have managed to do same few times.
    I do not get why rudimentary error such "missing reference" gets reported by "moc" and really does not point to the real source.
    To me "moc" errors are above "compiler error" and before "run time error".
    I am still getting few - " moc' file removed from disk - what do you want to do next?
    It would be nice for some learned person to explain how "moc" errors help in debugging - in general terms.
    And I do apologize for "me too" hijacking post.
    Cheers


Log in to reply