Suppose I add pushbutton in design mode. I click "go to the slot", thereby creating the onPushBotton_clicked method. In the future, I delete this button along with the code. As a result, later, when compiling, I get an error undefined reference to MainWindow::on_pushButton_clicked() . There is nothing valuable in the code, so I started anew, but still, how to delete widgets correctly so that no such errors occur later? And is it possible to do something if the error is already there? I tried to "clean everything" with rebuilding - it did not help

  • deleted the line void on_pushButton_clicked(); in mainwindow.h helped, but something tells me that this is not good ... - ASh
  • in .cpp, also delete the method body (if it remains) - gil9red
  • @ gil9red yes, deleted. It's enough? I do not leave the feeling that somewhere there is something left of this button. - ASh pm
  • Yes, good. The answer will tell more - gil9red

1 answer 1

When the designer created a method called on_pushButton_clicked , he “said” that there is a widget with objectName = pushButton and this method needs to be tied to the clicked signal of the widget.

Such methods are templates of the form: on_<objectName>_<signal> .

But having a method with such a name is not enough; you also need to call the QMetaObject::connectSlotsByName . When you created a ui file, Qt Creator based it created a cpp file in which the code created widgets on the form in the setupUi method and in this method connectSlotsByName is connectSlotsByName to bind the methods to the signals.

This is the dynamic linking of widget signals to methods.


Therefore, deleting the on_pushButton_clicked method from h / cpp files is sufficient. But I would also look in the form designer that this signal is deleted.

  • It seems to be deleted. Many thanks for the reply - ASh