Tag Archives: QSpinBox

QSpinBox: How to Solve Two signals with the same name processed error

QSpinBox has two signals with the same name
void valueChanged(int i)
void valueChanged(const QString &text)

When used like this
QObject::connect(&spinBox, SIGNAL(valueChanged(int)), ...)
QObject::connect(&spinBox, SIGNAL(valueChanged(QString)), ...)
is no problem.

When using syntax above C++11:
QObject::connect(&spinBox, &QSpinBox::valueChanged, ...)
The compiler will report an error:
error: no matching function for call to QObject::connect(QSpinBox*&, < unresolved overloaded function type>, ...)
The two signals cannot be distinguished using the function name.

At this time, you can use
auto qOverload(T functionPointer)
rewrite as
connect(spinbox, qOverload<int>(&QSpinBox::valueChanged), ...)