Glade:如何将多个参数传递给信号处理程序?

发布于 2024-08-27 17:26:15 字数 30 浏览 5 评论 0原文

Glade:如何将多个参数传递给信号处理程序?

Glade: How do I pass more than one argument to a signal handler?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

活泼老夫 2024-09-03 17:26:15

你在林间空地能做的事情非常有限。您可以将零个或一个对象作为用户数据传递给信号处理程序。该对象必须是也存在于林间空地项目中的小部件(或其他对象)。

另一方面,如果您从代码连接信号,则可以根据需要传递包含各种内容的结构。

如果您自己创建信号,则可以利用编组器创建所需的参数(对于信号处理程序原型),但仍然只有一个用户数据参数。因此,这不会让您指定更多参数然后连接信号,然后才调用它。

What you can do in glade is very limited. You can pass zero or one object as userdata to a signal handler. The object has to be a widget (or other object) also present in the glade project.

If you connect the signal from code on the other hand, you can pass a structure containing various stuff as you please.

And if you create signals yourself you can utilize marshallers to create how many arguments you want (for the signal handler prototype), but still just one userdata argument. So this will not let you specify more argument then connecting the signal, only then invoking it.

谎言月老 2024-09-03 17:26:15

从这里:

http://library. gnome.org/devel/gtkmm-tutorial/2.21/sec-connecting-signal-handlers.html.en
...

我们刚刚告诉您,按钮的单击信号期望调用不带参数的方法。所有信号都有这样的要求 - 您不能将带有两个参数的函数挂接到不期望任何参数的信号(当然,除非您使用适配器,例如 sigc::bind())。因此,了解您需要连接到给定信号的信号处理程序类型非常重要。

from here:

http://library.gnome.org/devel/gtkmm-tutorial/2.21/sec-connecting-signal-handlers.html.en
...

We just told you that the button's clicked signal is expecting to call a method with no arguments. All signals have requirements like this - you can't hook a function with two arguments to a signal expecting none (unless you use an adapter, such as sigc::bind(), of course). Therefore, it's important to know what type of signal handler you'll be expected to connect to a given signal.

清君侧 2024-09-03 17:26:15

为什么不直接获取应用程序加载时需要在事件处理程序中访问的每个对象的引用呢?如果将这些引用存储为全局变量,那么需要传递给事件处理程序的参数数量并不重要。所有 Gtk 小部件都可以在您的函数中使用,只要您认为合适。

Why don't you just simply obtain a reference to each of the objects that you need to access in the Event Handler when the application loads? If you store these references as global variables, then it wouldn't matter how many parameters you need to pass to the event handler. All of the Gtk Widgets would be available within your function to use however you see fit.

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