vs做网站视频教程,网站建设费钱吗,免费注册com域名,新乡门户网站建设方案现象 信号发送者找不到正确的信号函数 connect(ui-LSpinBox,QSpinBox::valueChanged,ui-hSlider,QSlider::setValue);QSpinBox的valueChanged函数分为int和QString两种#xff0c;存在函数重载#xff0c;需让编译器加以区分。 不区分的话会爆出#xff1…现象 信号发送者找不到正确的信号函数 connect(ui-LSpinBox,QSpinBox::valueChanged,ui-hSlider,QSlider::setValue);QSpinBox的valueChanged函数分为int和QString两种存在函数重载需让编译器加以区分。 不区分的话会爆出 error: C2664:
“QMetaObject::Connection QObject::connect(const QObject *,const char *,const char *,Qt::ConnectionType) const”:
无法将参数 2 从“overloaded-function”转换为“const char *”
解决方案
使用QOverload Qt5官方文档推荐使用的方式 connect(comboBox, QOverloadint::of(QComboBox::activated),[](int index){ /* ... */ });connect(comboBox, QOverloadconst QString ::of(QComboBox::activated),[](const QString text){ /* ... */ });auto qOverload(T functionPointer)
Returns a pointer to an overloaded function. The template parameter is the list of the argument types of the function. functionPointer is the pointer to the (member) function:struct Foo {void overloadedFunction();void overloadedFunction(int, const QString );};... qOverload(Foo::overloadedFunction)... qOverloadint, const QString (Foo::overloadedFunction)
If a member function is also const-overloaded qConstOverload and qNonConstOverload need to be used.
qOverload() requires C14 enabled. In C11-only code, the helper classes QOverload, QConstOverload, and QNonConstOverload can be used directly:... QOverload::of(Foo::overloadedFunction)... QOverloadint, const QString ::of(Foo::overloadedFunction)
Note: Qt detects the necessary C14 compiler support by way of the feature test recommendations from C Committees Standing Document 6.
This function was introduced in Qt 5.7.
See also qConstOverload(), qNonConstOverload(), and Differences between String-Based and Functor-Based Connections.
使用指针 创建一个函数指针用于保存指定的函数地址 void (QComboBox:: * activatedInt)(int) QComboBox::activated;
void (QComboBox:: * activatedString)(QString) QComboBox::activated;connect(comboBox, activatedInt,[](int index){ /* ... */ });connect(comboBox, activatedString,[](const QString text){ /* ... */ });