Qt - 信号槽中的参数

发布于 2024-08-25 03:25:57 字数 295 浏览 5 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

少女七分熟 2024-09-01 03:25:57

创建包含该功能的包装函数通常是最简单的。换句话说:

connect(pushbutton, SIGNAL(clicked()), SLOT(setDateFromCustomObject()));

然后,在调用 connect 的同一个类中:

void YourClass::setDateFromCustomObject() {
  dateEdit->setDate(custom_object.getDate());
}

可以通过使用名为 Qxt。他们的文档看起来并不完整或最新,但它们确实提供了一些不错的功能。我认为它仅适用于高级用户。

It's usually easiest to create a wrapper function that contains that functionality. In other words:

connect(pushbutton, SIGNAL(clicked()), SLOT(setDateFromCustomObject()));

And then, in the same class that calls connect:

void YourClass::setDateFromCustomObject() {
  dateEdit->setDate(custom_object.getDate());
}

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文