cominglately 2015-09-24 13:51 采纳率: 72.1%
浏览 2043
已采纳

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

         用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条回答 默认 最新

  • threenewbee 2015-09-24 15:39
    关注

    人家需要一个notebook,你传了一个button,检查下你的函数参数,传错了。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 odoo17关于owl开发js代码问题
  • ¥15 光纤中多普勒频移公式的推导
  • ¥15 怎么制作一个人脸识别门禁系统
  • ¥20 大华dss监控平台网络关闭登不进去
  • ¥15 请使用蚁群算法解决下列问题,并给出我完整的代码
  • ¥20 关于php录入完成后,批量更新数据库
  • ¥15 请教往复密封润滑问题
  • ¥15 cocos creator发布ios包
  • ¥15 comsol压电材料数据
  • ¥35 用python实现除法算法中goldschmidt算法