我正在尝试访问GTK Widget
,现在小部件的任何属性都可以,但我不断收到错误消息:
Gtk-CRITICAL **: IA__FUNCTIONAME: assertion `GTK_IS_WIDGET (widget)' failed
到目前为止,这是我的代码,以及相关位:
///////// FILE 1 /////////////////
GtkWidget *textbox1; //declared at the top of the file
GtkTextBuffer *text;
void onscreen (int type, char* key)
{
if (type == -1) {
//remove widget
}
else if (type == 1) {
gtk_widget_destroy(GTK_WIDGET(textbox1));
//THE OFFENDING LINE ^^^
}
}
int main (int argc, char *argv[])
{
gtk_init(&argc, &argv);
/*more code*/
textbox1 = gtk_text_view_new();
text = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textbox1));
GtkTextIter iter;
gtk_text_buffer_get_iter_at_offset(text, &iter, 0);
gtk_text_buffer_insert(text, &iter, "plain text\n", -1);
vbox = gtk_vbox_new(FALSE, 8);
gtk_container_add(GTK_CONTAINER(window), vbox);
gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(vbox), zbarwidgets, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(results), FALSE, FALSE, 0);
gtk_widget_show_all(window);
gtk_main();
return(0);
}
///////// FILE 1 /////////////////
然后我在另一个文件中有更多代码(标题等......都很好),它调用文件2中的第一个函数,如下所示:
///////// FILE 2 /////////////////
static inline int window_draw (window_t *w) {
/* do some stuff */
onscreen(1, sym->data);
/* do some stuff */
}
///////// FILE 2 /////////////////
谢谢!