g_signal_connect_swapped() 的作用是什么?
根据GObject参考
g_signal_connect_swapped(实例、detailed_signal、c_handler、数据);将 GCallback 函数连接到特定对象的信号。发出信号的实例和调用处理程序时将交换数据的实例。
我不太明白这意味着什么。这是否意味着 data
将指向 instance
所指向的对象,而 instance
将指向 instance
所指向的对象>data 或者我在这里犯了一个错误?
如果是前者,那么这背后的逻辑是什么?
According to GObject reference
g_signal_connect_swapped(instance, detailed_signal, c_handler, data); connects a GCallback function to a signal for a particular object. The instance on which the signal is emitted and data will be swapped when calling the handler.
I don't quite get what this means. Does this mean that the data
will point to the object pointed to byinstance
and instance
will point to the object that was pointed to by data
or am I making a mistake here?
If former is the case then what is the logic behind this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你理解正确。
这允许您执行如下操作:您有一个按钮(我们称之为
button
),按下时应该隐藏另一个小部件(我们称之为textview
) 。然后你就可以做到
这一点。当按钮被按下时,它会生成“clicked”信号,并使用
textview
作为第一个参数和button
作为第二个参数来调用回调。在本例中,回调函数是gtk_widget_hide()
,它只接受一个参数,因此第二个参数被忽略,因为这就是 C 调用约定的工作方式。它与以下内容相同,但更短。
基本上,如果您手动编写界面代码,它可以使您不必编写额外的函数。当然,可能还有一些我从未理解过的更实际的用途。
You understand correctly.
This allows you to do tricks like the following: You have a button (let's call it
button
), that is supposed to hide another widget (let's call ittextview
) when pressed.You can then do
to achieve that. When the button is pressed, it generates the 'clicked' signal, and the callback is called with
textview
as the first argument, andbutton
as the second. In this case the callback isgtk_widget_hide()
which only takes one argument, so the second argument is ignored, because that's the way the C calling convention works.It's the same as the following, but shorter.
Basically it saves you from having to write an extra function if you hand-code your interface. Of course, there may be some far more practical use that I've never understood.