Qt - 信号槽中的参数
我有一个 QPushButton、QDateEdit 和另一个自定义对象。我想将按钮连接到日期编辑对象,当我单击按钮时,日期编辑对象会将其设置日期更改为自定义对象上定义的日期。有点像这样:
connect(pushbutton,SIGNAL(clicked()),dateedit,SLOT(setDate(custom_object.getDate())));
但我做不到。显然,connect 语句没有指定从信号传递到槽的信息是什么,只指定了传递的信息的类型。有没有一种方法可以做到这一点而无需创建新类?
I have a QPushButton, QDateEdit and another custom object. I want to connect the button to the date edit object in a way that when I click the button, the date edit object will change its set date to a date defined on the custom object. Kinda like this:
connect(pushbutton,SIGNAL(clicked()),dateedit,SLOT(setDate(custom_object.getDate())));
but I can't do that. Apparently, the connect statement doesn't specify what's the information being passed from the signal to the slot, only the type of the information being passed. Is there a way to do this without having to create a new class?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
创建包含该功能的包装函数通常是最简单的。换句话说:
然后,在调用 connect 的同一个类中:
可以通过使用名为 Qxt。他们的文档看起来并不完整或最新,但它们确实提供了一些不错的功能。我认为它仅适用于高级用户。
It's usually easiest to create a wrapper function that contains that functionality. In other words:
And then, in the same class that calls connect:
It is possible to do connect time binding with specific arguments and objects through the use of an external library called Qxt. It doesn't look like their documentation is complete or up-to-date, but they do provide some nice functionality. I consider it for advanced users only.