QMetaObject::connectSlotsByName: No matching signal for on_{Object_Name}_valueChanged(int)
-
Re: No matching signal for ...[SOLVED]
I created a spinBox widget and tried connecting it to the valueChanged (int arg1) signal. The slot body is auto-generated. However, the slot is not triggered, and the application window complains - "QMetaObject::connectSlotsByName: No matching signal for on_{Object_Name}_valueChanged(int)."
I have other spinBoxes connected to the same signal, i.e., valueChanged9int arg1), and they work fine. I would appreciate help on this topic. This is what has been tried so far after going through various forums. None worked.
- Cleaned the project and re-built and no luck.
- Removed the "on_" from the slot name and no luck.
I am using MSVC2017 to build the software.
-
Hi and welcome to devnet,
While the feature is relatively nice, it's rather easy to trip it. The usual recommendation is to only use explicit connections. That way you ensure that everything you want is properly connected and if you change your widget name, you only have one place to change to keep it working.
-
@SGaist Thanks for your quick response.
I agree with your suggestion. I tried the same, and it pointed to the root of the actual issue. So, my GUI form name is "gui_input.ui," and the auto-generated header is "ui_gui_inputif.h". I observed that when I make changes to the form (E.g., adding a new SpinBox or Button object) and save -> clean -> run q make -> Build & Run, the "ui_gui_inputif.h" is not reflecting my changes.
So, as a next step, I modified the file manually and added the object (replicated the code for another object that seems to work fine).
After that, I tried connecting the signal and slot with the below syntax.
GUI_InputIf::GUI_InputIf(QWidget *parent) :
QDialog(parent),
ui(new Ui::GUI_InputIf)
{
ui->setupUi(this);connect(ui->LKA_L_STS, SIGNAL(valueChanged(int)), this, SLOT(LKA_L_STS_valueChanged(int)));
}
This is how my class declaration looks like:-
class GUI_InputIf : public QDialog
{
Q_OBJECTpublic:
GUI_InputIf(QWidget *parent);~GUI_InputIf();
private slots:
void LKA_L_STS_valueChanged(int arg1);private:
Ui::GUI_InputIf *ui;
}This did NOT work. It did not see the slot called on changing the spinBox value.
As a next step, I created my own signal and added it to the class. (See code below).
class GUI_InputIf : public QDialog
{
Q_OBJECTpublic:
GUI_InputIf(QWidget *parent);~GUI_InputIf();
private slots:
void LKA_L_STS_valueChanged(int arg1);signals:
void lkaValChanged(int arg1);private:
Ui::GUI_InputIf *ui;
}No luck with this as well. I am unsure how to make the spinBox trigger this signal on value change such that the slot is triggered. From where should I emit this signal?
-
@AbhimanyuD
Generally, please format posted code. It’s just so much easier to read for everybody.
What exactly happens in the modified example?
Autoconnect by name will not work without the on_
Have you tried connecting the PMF way?