[英]Passing a struct of Gtk Widgets to a callback function
I'm creating a GTK+ application in C,where i need to destroy a widget (for ex: a button) from a callback function.When i call "gtk_widget_destroy" from the function,the widget doesn't get destroyed and i see the following warnings: 我正在C语言中创建一个GTK +应用程序,在这里我需要从回调函数中销毁一个小部件(例如:按钮)。当我从该函数调用“ gtk_widget_destroy”时,该小部件不会被销毁,并且我看到以下警告:
(gtkTest:9150): GLib-GObject-WARNING **: invalid uninstantiatable type 'GInterface' in cast to 'GtkObject'
(gtkTest:9150): Gtk-CRITICAL **: IA__gtk_widget_destroy: assertion 'GTK_IS_WIDGET (widget)' failed
how do i access the button widget from inside a callback function ? 如何从回调函数内部访问按钮小部件? The only i option i see it is to make this widget global.Any help will be greatly appreciated.
我看到的唯一我的选择是使此小部件成为全局小部件。任何帮助将不胜感激。
The code snippet is as follows: 代码片段如下:
typedef struct {
GtkWidget *button;
} buttonInfo;
/*call back function */
static gpointer _callBackFunc (buttonInfo *buttonTable)
{
/*do some stuff*/
gtk_widget_destroy(buttonTable->button);
//
return(NULL);
}
/*main*/
int main( int argc, char *argv[])
{
GtkWidget *testButton;
buttonInfo *buttonPTR;
buttonPTR = g_new(buttonInfo,1);
testButton = gtk_button_new_with_label("Click Me");
buttonPTR->button = (GtkWidget *) testButton;
g_signal_connect(G_OBJECT(testButton),"activate",
G_CALLBACK(_callBackFunc),buttonPTR);
/*This works */
//gtk_destroy_widget(buttonPTR->button);
}
Your callback function signature must match the signature you see in the signal documentation . 您的回调函数签名必须与您在信号文档中看到的签名匹配。 In the case of "activate", it should be
在“激活”的情况下,应该
static void _callBackFunc (GtkButton *button, gpointer user_data)
{
buttonInfo *button_info = (buttonInfo *)user_data;
// ...
}
That said, while you are checking the signature do read the rest of activate-signal documentation: it's probably not the signal you want to use (see "clicked"). 也就是说,在检查签名时,请阅读激活信号文档的其余部分:这可能不是您要使用的信号(请参见“单击”)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.