cominglately
cominglately
2015-09-24 13:51

gtk+图形编程的时候出现的错误,怎么破?invalid cast

  • gtk+
  • 图形
         用GtkButton发出“clicked”信号传递GtkNotebook参数,以在回调函数中调用gtk_notebook_remove_page函数,出错

    GLib-GObject-WARNING **: invalid cast from 'GtkButton' to 'GtkNotebook'
 源码:
      button=gtk_button_new_with_label("tab_os");
  119     g_signal_connect_swapped(GTK_OBJECT(button),"clicked",G_CALLBACK(tab_po),notebook);  
  120     gtk_table_attach_defaults(GTK_TABLE(table),button,2,3,1,2);
         回调函数:
   void tab_po(GtkWidget*widget,gpointer notebook)
  24    {
    25    gtk_notebook_set_tab_pos(GTK_NOTEBOOK(notebook),GTK_POS_BOTTOM);
  26    }


         用GtkButton发出“clicked”信号传递GtkNotebook参数,以在回调函数中调用gtk_notebook_remove_page函数,出错
 1  #include
 2  #include
 3  GtkWidget*entry;
 4  void notebook_remove(GtkWidget*button,gpointer notebook)
 5  {
 6    gint page;
 7    gchar buffer[20];
 8    page=gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook));
 9    snprintf(buffer,20,"It is the %dth page",page);
10    gtk_entry_set_text(GTK_ENTRY(entry),buffer);
11    gtk_notebook_remove_page(GTK_NOTEBOOK(notebook),page);
12  }
13  int main(int argc,char**argv)
14  {
15    GtkWidget*window;
16    GtkWidget*tabel;
17    GtkWidget*notebook;
18    GtkWidget*button;
19    GtkWidget*label;
20    gchar bufferl[40];
21    gint i;
22    gtk_init(&argc,&argv);
23    window=gtk_dialog_new();
24    gtk_window_set_default_size(GTK_WINDOW(window),600,200);
25    notebook=gtk_notebook_new();
26    for(i=0;ivbox),notebook,FALSE,FALSE,0);
33    entry=gtk_entry_new();
34    gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window)->vbox),entry,FALSE,FALSE,0);
35    gtk_entry_set_text(GTK_ENTRY(entry),"Nothing happens");
36    button=gtk_button_new_with_mnemonic("remove");
37    gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window)->action_area),button,FALSE,FALSE,0);
38    g_signal_connect_swapped(GTK_OBJECT(button),"clicked",G_CALLBACK(notebook_remove),notebook);
39    button=gtk_button_new_with_label("close app");
40    gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window)->action_area),button,FALSE,FALSE,0);
41    g_signal_connect(GTK_OBJECT(button),"clicked",G_CALLBACK(gtk_main_quit),NULL);
42    gtk_widget_show_all(window);
43    gtk_main();
44    return 0;
45  }
46    
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答