简体   繁体   English

GTK:回调函数签名概述

[英]GTK: Overview of callback function signatures

In a GTK2 application a user-defined callback function can be called when certain events occur, eg, like this: 在GTK2应用程序中,当某些事件发生时,可以调用用户定义的回调函数,例如:

static void on_destroy(GtkObject* o) {
    gtk_main_quit();
}

int main(int argc, char * argv[]) {
    ...    
    g_signal_connect(window1, "destroy", G_CALLBACK(on_destroy), NULL);
    ...
}

The signature of the callback functions depends on the type of signal or event. 回调函数的签名取决于信号或事件的类型。 I was looking for an concise overview of those signatures and I found a chapter about signals in the GTK+ 2.0 tutorial . 我一直在寻找这些签名的简要概述,并且在GTK + 2.0教程中找到了有关信号章节 However, it seems to be missing the callback signatures for the GtkTreeview signals, like row-activated , select-cursor-row etc. 但是,它似乎缺少了GtkTreeview信号的回调签名,例如row-activatedselect-cursor-row等。

Are there any other sources that describe the correct implementation of all callback signatures, preferably in a concise overview and not spread out over several chapters? 是否有其他来源描述所有回调签名的正确实现,最好是在简洁的概述中,而不是分散在几章中?

You should check the Gtk+ 2 Reference Manual 您应该查看Gtk + 2参考手册

For example, the destroy signal being connected in your example comes from one of the GtkWindow parent classes, GtkObject 例如,在您的示例中连接的销毁信号来自GtkWindow父类之一GtkObject

The “destroy” signal “破坏”信号

void user_function (GtkObject *object, gpointer user_data)

Check the Tree, List Widgets for relevant signals and respective prototypes: 检查“树”,“列表小部件”以获取相关信号和相应的原型:

https://developer.gnome.org/gtk2/stable/TreeWidgetObjects.html https://developer.gnome.org/gtk2/stable/TreeWidgetObjects.html

Notice: Parent classes doesn't mean multiple inheritance, just a class above in the inheritance hierarchy. 注意:父类并不意味着多重继承,而只是继承层次中位于上方的一个类。

You need to learn how to use the official help. 您需要学习如何使用官方帮助。 On each widget help page, there's a navigation bar at the top. 在每个小部件帮助页面上,顶部都有一个导航栏。 There you have direct links to the signals, the object hierarchy (parent classes), etc. 在这里,您可以直接链接到信号,对象层次结构(父类)等。

So if you're looking for a specific signal for a widget, you just go to that widget help page, then click on the "signals" link in the navigation bar. 因此,如果您正在寻找小部件的特定信号,则只需转到该小部件帮助页面,然后单击导航栏中的“信号”链接即可。 If the signal is not there, then it must be in a parent class. 如果信号不存在,则它必须在父类中。 So you click on the "object hierarchy" link which sends you to the widget's inheritance tree. 因此,您单击“对象层次结构”链接,该链接将您带到小部件的继承树。 You click ont its parent and search for the signal again. 您单击其父级,然后再次搜索该信号。

Alternatively, you may install the devhelp help browser that comes installed with your Linux distro (or in MSYS2 for Windows). 或者,您可以安装Linux发行版(或Windows的MSYS2)中随附的devhelp帮助浏览器。 There is a search field where you can just type the name of the symbol you're looking for, signals included. 有一个搜索字段,您可以在其中键入要查找的符号的名称,包括信号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM