创建并发出信号GTK [英] create and emit gtk signal

查看:298
本文介绍了创建并发出信号GTK的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建并发出一个信号GTK:

I am trying to create and emit a GTK signal:

g_signal_new("child-finished",
    G_TYPE_OBJECT,
    G_SIGNAL_RUN_FIRST,
    0,
    NULL, NULL,
    NULL,           // *** I think this is where I need to change it
    G_TYPE_NONE, 0);
g_signal_connect(G_OBJECT(myWindow), "child-finished", G_CALLBACK(MyCallback), NULL);

下面是我的code发出信号:

Here is my code that emits the signal:

gtk_signal_emit_by_name(referenceToMyWindow, "child-finished");

这是我的code处理该信号:

And here is my code that handles the signal:

void MyCallback(GtkWidget *w, GdkEvent *e)
{
    // handler code here
}

当我运行code我得到以下错误:

When I run the code I get the following error:

GLib的-的GObject-CRITICAL **:摹 _closure _ 调用:断言`closure->元帅|| closure-> meta_marshal'失败

GLib-GObject-CRITICAL **: g_closure_invoke: assertion `closure->marshal || closure->meta_marshal' failed

我知道它是与传递一个编组到 g_signal_new 的功能,但我不知道编组是什么,我不明白<一个HREF =htt​​p://library.gnome.org/devel/gobject/unstable/gobject-Closures.html#GClosureMarshal相对=nofollow>文档和在线的例子是少之又少。我如何声明和连接我自己的信号?

I know it has something to do with passing a marshaller to the g_signal_new function, but I don't know what a marshaller is, I can't understand the documentation, and the examples online are few and far between. How do I declare and connect my own signal?

推荐答案

GObject的库提供了一些的内置marshallers 的,所以你的code可能应该:

The GObject library provides some builtin marshallers, so your code should probably be:

g_signal_new("child-finished",
             G_TYPE_OBJECT, G_SIGNAL_RUN_FIRST,
             0, NULL, NULL,
             g_cclosure_marshal_VOID__POINTER,
             G_TYPE_NONE, 1, G_TYPE_POINTER);

或者,如果你想要的类型检查:

or, if you want type checking:

g_signal_new("child-finished",
             G_TYPE_OBJECT, G_SIGNAL_RUN_FIRST,
             0, NULL, NULL,
             g_cclosure_marshal_VOID__BOXED,
             G_TYPE_NONE, 1, GDK_TYPE_EVENT);

信号处理函数的参数必须是present(itsself隐含的对象),所以一定要指定一个指针(如在第一个例子)或盒装类型(如在第二个例子)。

The parameters of the signal handler must be present (the object itsself is implied), so be sure to specify a pointer (as in the first example) or a boxed type (as in the second example).

如果您需要的编组是不是在那些建宏present,您可以使用的巧舌如簧-genmarshal 实用程序或直接code它自己(这是很微不足道的,只是签巧舌如簧,genmarshal的输出)。

If the marshaller you need is not present in the builtins ones, you could use the glib-genmarshal utility or directly code it by yourself (it is quite trivial, just checkout the output of glib-genmarshal).

这篇关于创建并发出信号GTK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆