我能够找到创建和发出新信号的唯一例子是gnome developer site,它提供了以下示例:
file = g_object_new (MAMAN_FILE_TYPE, NULL);
g_signal_connect (file, "changed", G_CALLBACK (changed_event), NULL);
maman_file_write (file, buffer, strlen (buffer));
/* ------------------ */
file_signals[CHANGED] =
g_signal_newv ("changed",
G_TYPE_FROM_CLASS (gobject_class),
G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
NULL /* closure */,
NULL /* accumulator */,
NULL /* accumulator data */,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE /* return_type */,
0 /* n_params */,
NULL /* param_types */);
/* ------------------ */
void maman_file_write (MamanFile *self, const guchar *buffer, gssize size)
{
/* First write data. */
/* Then, notify user of data written. */
g_signal_emit (self, file_signals[CHANGED], 0 /* details */);
}
我想知道的一件事是,是否可以发出没有GObject作为源的信号 - 以及是否可以传递非Gobject结构。 为简单起见,假设我有一个创建点对象的函数,并且我想在创建一个点时发出一个信号(假设有一些GtkWidget在创建一个点时显示某些东西):
struct point {
int x,y;
};
struct point *new_point(int x, int y) {
struct point *my_point = malloc(sizeof(point));
my_point->x= x;
my_point->y= y;
/* ???
g_signal_emit "point-created"
send pointer to my_point as a parameter to listeners
*/
return my_point;
}
如果没有创建新G_OBJECT_TYPE的所有锅炉板,是否有办法制作类似于较低工作的东西?