插槽中的多个参数
想要将两个参数传递给插槽。我有uii-> spinbox
,它有两个信号valuechanged(int)
和value echanged(qString)
。我这样做:
connect(ui->spinBox,&QSpinBox::valueChanged, [&](){ this->ChangeParamCurve(ui->spinBox_11->value(),0);});
出现错误:
错误:呼叫“连接”的匹配成员函数 Qobject.h:463:41:注意:候选功能不可行:没有超负荷 第二个论点的“估值”匹配'const char *' Qobject.h:260:13:注意:候选模板被忽略:无法推断 模板参数“ func1” qobject.h:300:13:注意:候选模板 忽略:无法推断模板参数'func1'qobject.h:208:36: 注意:候选功能不可行:至少需要4个参数, 但是提供了3个Qobject.h:211:36:注意:候选功能不 可行:至少需要4个论点,但提供了3个论点 Qobject.h:228:43:注意:候选功能模板不可行: 需要至少4个论点,但提供了3个论点。H:269:13: 注意:候选功能模板不可行:至少需要4个 争论,但提供了3个Qobject.h:308:13:注意:候选人 功能模板不可行:需要至少4个参数,但3个参数 提供了
我认为QT不能像这样接受超载信号或SMTH。 有什么想法吗?
Want to pass two arguments to the slot. I have ui->spinBox
, it has two signals valueChanged(int)
and valueChanged(QString)
. I'm doing like that:
connect(ui->spinBox,&QSpinBox::valueChanged, [&](){ this->ChangeParamCurve(ui->spinBox_11->value(),0);});
Appears error:
error: no matching member function for call to 'connect'
qobject.h:463:41: note: candidate function not viable: no overload of
'valueChanged' matching 'const char *' for 2nd argument
qobject.h:260:13: note: candidate template ignored: couldn't infer
template argument 'Func1' qobject.h:300:13: note: candidate template
ignored: couldn't infer template argument 'Func1' qobject.h:208:36:
note: candidate function not viable: requires at least 4 arguments,
but 3 were provided qobject.h:211:36: note: candidate function not
viable: requires at least 4 arguments, but 3 were provided
qobject.h:228:43: note: candidate function template not viable:
requires at least 4 arguments, but 3 were provided qobject.h:269:13:
note: candidate function template not viable: requires at least 4
arguments, but 3 were provided qobject.h:308:13: note: candidate
function template not viable: requires at least 4 arguments, but 3
were provided
I think that qt can't accept overloaded signals or smth like that.
Any thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如 docs 连接到此信号时使用QOVERLOAD。
同样,有多少参数
thickparamcurve
接受了多少参数。 lambda函数是在此处连接的插槽。它应该完全采用一个参数,因为那是信号发送的内容。但是在lambda中,您可以使用任意数量的参数调用函数。As shown in the docs that @chehrlic pointed out, you need to use QOverload when connecting to this signal.
Also, it doesn't matter how many parameters
ChangeParamCurve
takes. The lambda function is the slot that is being connected here. And it should take exactly one parameter, since that is what the signal is sending. But within the lambda, you can call functions with any number of parameters.您可以自己从
spinbox
类得出对象。您将能够根据需要在其中添加信号和插槽。我曾经做过这样的事情,因为
qlineedit
没有“焦点”事件。让我对我为qlineedit
>> Qline>的主要思想提出。如果您想有一个集中的信号,则必须得出
qlineedit
类。这是如何实现这一目标的示例。在
mylineedit.h
文件中,您有:在
mylineedit.cpp
文件中,您拥有:您现在可以连接
mylineEdit :: focussed()
>向您的focus()
方法(插槽)发出信号。以同样的方式,两个事件可以使用自定义参数触发您的自定义事件。同样,如果愿意,您可以通过右键单击并使用
propers propers propers
方法将这些功能添加到现有的spinbox
,从设计师那里添加到。You can derive an object from the
spinbox
class yourself. You would be able to add signals and slots to it as you want.I once did something like this because there was no "focus" event for
qlineedit
. Let me throw in the main idea of what I wrote forqlineedit
.If you want to have a focused signal, you will have to derive the
QLineEdit
class. Here is a sample of how this can be achieved.In the
myLineEdit.h
file you have:In the
myLineEdit.cpp
file you have:You can now connect the
MyLineEdit::focussed()
signal to yourfocus()
method (slot).In the same way two events can trigger your custom event with custom parameters. Again, if you wish, you can add these features to an existing
spinbox
, from the Designer, by right-clicking and using thePromote to
method.