LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1394|回复: 4

想弄没这些信息,怎么办。如下:(gtk linux menu)

[复制链接]
发表于 2003-11-16 22:26:05 | 显示全部楼层 |阅读模式

  1. wide288@~/stock/dir-1_ep$ make
  2. gcc -g stock-1.c -o stock.elf `pkg-config --cflags --libs gtk+-2.0`
  3. stock-1.c:27: warning: initialization makes integer from pointer without a cast
  4. stock-1.c:28: warning: initialization makes integer from pointer without a cast
  5. stock-1.c:29: warning: initialization makes integer from pointer without a cast
  6. stock-1.c:30: warning: initialization makes integer from pointer without a cast
  7. stock-1.c:32: warning: initialization makes integer from pointer without a cast
  8. stock-1.c:34: warning: initialization makes integer from pointer without a cast
  9. stock-1.c:35: warning: initialization makes integer from pointer without a cast
  10. stock-1.c:36: warning: initialization makes integer from pointer without a cast
  11. stock-1.c:37: warning: initialization makes integer from pointer without a cast
  12. stock-1.c:39: warning: initialization makes integer from pointer without a cast
  13. stock-1.c:40: warning: initialization makes integer from pointer without a cast
  14. wide288@~/stock/dir-1_ep$

复制代码
 楼主| 发表于 2003-11-16 22:26:55 | 显示全部楼层
原代码:

  1. #include <gtk/gtk.h>
  2. void on_menu_activate(GtkMenuItem* item,gpointer data);

  3. static GtkItemFactoryEntry menu_items[] ={
  4. {"/文件 (_F) ",NULL,NULL,0,"<Branch>"},
  5. {"/文件 (_F) /新建", NULL, on_menu_activate, "新建","<StockItem>", GTK_STOCK_NEW},
  6. {"/文件 (_F) /打开",NULL,on_menu_activate,"打开","<StockItem>",GTK_STOCK_OPEN},
  7. {"/文件 (_F) /保存",NULL, on_menu_activate,"保存", "<StockItem>", GTK_STOCK_SAVE},
  8. {"/文件 (_F) /另存为", NULL, on_menu_activate,"另存为","<StockItem>",GTK_STOCK_SAVE_AS},
  9. {"/文件 (_F) /-",NULL,NULL,0,"<Separator>"},
  10. {"/文件 (_F) /退出", NULL, on_menu_activate, "退出", "<StockItem>", GTK_STOCK_QUIT},
  11. {"/编辑 (_E) ", NULL,NULL,0,"<Branch>"},
  12. {"/编辑 (_E) /剪切",NULL,on_menu_activate,"剪切","<StockItem>",GTK_STOCK_CUT},
  13. {"/编辑 (_E) /复制",NULL,on_menu_activate,"复制","<StockItem>",GTK_STOCK_COPY},
  14. {"/编辑 (_E) /粘贴",NULL, on_menu_activate,"粘贴", "<StockItem>", GTK_STOCK_PASTE},
  15. {"/编辑 (_E) /查找",NULL, on_menu_activate,"查找","<StockItem>",GTK_STOCK_FIND},
  16. {"/帮助 (_H) ",NULL,NULL,0,"<LastBranch>"},
  17. {"/帮助 (_H) /帮助", NULL, on_menu_activate, "帮助", "<StockItem>", GTK_STOCK_HELP},
  18. {"/帮助 (_H) /关于...", NULL, on_menu_activate, "关于", NULL}
  19. };

  20. void on_menu_activate (GtkMenuItem* item, gpointer data)
  21. {
  22. g_print("菜单项");
  23. g_print("  %s  ",(gchar*)data);
  24. g_print("被激活\n");
  25. }

  26. int main(int argc, char *argv[])
  27. {
  28. GtkWidget* window;
  29. GtkWidget* box;
  30. GtkWidget* menubar;
  31. GtkAccelGroup* accel_group;
  32. GtkItemFactory* item_factory;
  33. gint n=15;
  34. gtk_init(&argc,&argv);
  35. window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
  36. gtk_window_set_title(GTK_WINDOW(window),"添加菜单的快捷方法");
  37. g_signal_connect(G_OBJECT(window),"destroy",
  38.                                 G_CALLBACK(gtk_main_quit),NULL);

  39. accel_group=gtk_accel_group_new();
  40. box=gtk_vbox_new(FALSE,0);
  41. gtk_container_add(GTK_CONTAINER(window),box);
  42. gtk_widget_show(box);

  43. item_factory=gtk_item_factory_new(GTK_TYPE_MENU_BAR,"<main>",accel_group);
  44. gtk_item_factory_create_items(item_factory,n, menu_items,NULL);
  45. gtk_window_add_accel_group(GTK_WINDOW(window),accel_group);
  46. menubar=gtk_item_factory_get_widget(item_factory,"<main>");
  47. gtk_box_pack_start(GTK_BOX(box),menubar,FALSE,FALSE,0);
  48. gtk_widget_show(menubar);
  49. gtk_widget_show(window);
  50. gtk_main();
  51. return FALSE;
  52. }
复制代码
 楼主| 发表于 2003-11-17 22:27:22 | 显示全部楼层
成了,警告弄没了,可是不是这个代码段,是别的,现在也不知道为什么会出现的。不过一定不是gtk 的问题,是我的问题。
看来是可以写出没有警告的代码的。这点很重要。
发表于 2003-11-18 19:39:07 | 显示全部楼层
makes integer from pointer without a cast
中文意义如下

从指针转换到一个INT类但是没有经过类型转换
 楼主| 发表于 2003-11-18 23:38:54 | 显示全部楼层
gcc -g stock-1.c -o stock.elf `pkg-config --cflags --libs gtk+-2.0`
stock-1.c:44: warning: initialization makes integer from pointer without a cast

谢谢版主,我找到问题了,是如下:
{ "/文件F/_New",     "<control>N", on_menu_activate, "新建", NULL },
这句中的,参数 不能是字符串,应是int 型 的,而用了字符串还可以用,只是有警告。找了几个月了,终于找到了。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表