当前位置: 技术问答>linux和unix
gtk2,书中例题出错:2.2节,快捷菜单
来源: 互联网 发布时间:2015-03-06
本文导语: itemfact]$ make gcc itemfact.c -o itemfact `pkg-config gtk+-2.0 --cflags --libs` itemfact.c:6: warning: initialization makes integer from pointer without a cast itemfact.c:7: warning: initialization makes integer from pointer without a cast itemfact.c:8: war...
itemfact]$ make
gcc itemfact.c -o itemfact `pkg-config gtk+-2.0 --cflags --libs`
itemfact.c:6: warning: initialization makes integer from pointer without a cast
itemfact.c:7: warning: initialization makes integer from pointer without a cast
itemfact.c:8: warning: initialization makes integer from pointer without a cast
itemfact.c:9: warning: initialization makes integer from pointer without a cast
itemfact.c:11: warning: initialization makes integer from pointer without a cast
itemfact.c:13: warning: initialization makes integer from pointer without a cast
itemfact.c:14: warning: initialization makes integer from pointer without a cast
itemfact.c:15: warning: initialization makes integer from pointer without a cast
itemfact.c:16: warning: initialization makes integer from pointer without a cast
itemfact.c:18: warning: initialization makes integer from pointer without a cast
itemfact.c:19: warning: initialization makes integer from pointer without a cast
以上是出错信息,我想把它弄没,最好能说清楚来龙去脉。谢谢了。以下是原程序。:
--------------------------------------------------------------------------
#include
void on_menu_activate(GtkMenuItem* item,gpointer data);
static GtkItemFactoryEntry menu_items[] ={
{"/文件 (_F) ",NULL,NULL,0,""},
{"/文件 (_F) /新建", NULL, on_menu_activate, "新建","", GTK_STOCK_NEW},
{"/文件 (_F) /打开",NULL,on_menu_activate,"打开","",GTK_STOCK_OPEN},
{"/文件 (_F) /保存",NULL, on_menu_activate,"保存", "", GTK_STOCK_SAVE},
{"/文件 (_F) /另存为", NULL, on_menu_activate,"另存为","",GTK_STOCK_SAVE_AS},
{"/文件 (_F) /-",NULL,NULL,0,""},
{"/文件 (_F) /退出", NULL, on_menu_activate, "退出", "", GTK_STOCK_QUIT},
{"/编辑 (_E) ", NULL,NULL,0,""},
{"/编辑 (_E) /剪切",NULL,on_menu_activate,"剪切","",GTK_STOCK_CUT},
{"/编辑 (_E) /复制",NULL,on_menu_activate,"复制","",GTK_STOCK_COPY},
{"/编辑 (_E) /粘贴",NULL, on_menu_activate,"粘贴", "", GTK_STOCK_PASTE},
{"/编辑 (_E) /查找",NULL, on_menu_activate,"查找","",GTK_STOCK_FIND},
{"/帮助 (_H) ",NULL,NULL,0,""},
{"/帮助 (_H) /帮助", NULL, on_menu_activate, "帮助", "", GTK_STOCK_HELP},
{"/帮助 (_H) /关于...", NULL, on_menu_activate, "关于", NULL}
};
void on_menu_activate (GtkMenuItem* item, gpointer data)
{
g_print("菜单项");
g_print(" %s ",(gchar*)data);
g_print("被激活n");
}
int main(int argc, char *argv[])
{
GtkWidget* window;
GtkWidget* box;
GtkWidget* menubar;
GtkAccelGroup* accel_group;
GtkItemFactory* item_factory;
gint n=15;
gtk_init(&argc,&argv);
window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window),"添加菜单的快捷方法");
g_signal_connect(G_OBJECT(window),"destroy",
G_CALLBACK(gtk_main_quit),NULL);
accel_group=gtk_accel_group_new();
box=gtk_vbox_new(FALSE,0);
gtk_container_add(GTK_CONTAINER(window),box);
gtk_widget_show(box);
item_factory=gtk_item_factory_new(GTK_TYPE_MENU_BAR,"",accel_group);
gtk_item_factory_create_items(item_factory,n, menu_items,NULL);
gtk_window_add_accel_group(GTK_WINDOW(window),accel_group);
menubar=gtk_item_factory_get_widget(item_factory,"");
gtk_box_pack_start(GTK_BOX(box),menubar,FALSE,FALSE,0);
gtk_widget_show(menubar);
gtk_widget_show(window);
gtk_main();
return FALSE;
}
gcc itemfact.c -o itemfact `pkg-config gtk+-2.0 --cflags --libs`
itemfact.c:6: warning: initialization makes integer from pointer without a cast
itemfact.c:7: warning: initialization makes integer from pointer without a cast
itemfact.c:8: warning: initialization makes integer from pointer without a cast
itemfact.c:9: warning: initialization makes integer from pointer without a cast
itemfact.c:11: warning: initialization makes integer from pointer without a cast
itemfact.c:13: warning: initialization makes integer from pointer without a cast
itemfact.c:14: warning: initialization makes integer from pointer without a cast
itemfact.c:15: warning: initialization makes integer from pointer without a cast
itemfact.c:16: warning: initialization makes integer from pointer without a cast
itemfact.c:18: warning: initialization makes integer from pointer without a cast
itemfact.c:19: warning: initialization makes integer from pointer without a cast
以上是出错信息,我想把它弄没,最好能说清楚来龙去脉。谢谢了。以下是原程序。:
--------------------------------------------------------------------------
#include
void on_menu_activate(GtkMenuItem* item,gpointer data);
static GtkItemFactoryEntry menu_items[] ={
{"/文件 (_F) ",NULL,NULL,0,""},
{"/文件 (_F) /新建", NULL, on_menu_activate, "新建","", GTK_STOCK_NEW},
{"/文件 (_F) /打开",NULL,on_menu_activate,"打开","",GTK_STOCK_OPEN},
{"/文件 (_F) /保存",NULL, on_menu_activate,"保存", "", GTK_STOCK_SAVE},
{"/文件 (_F) /另存为", NULL, on_menu_activate,"另存为","",GTK_STOCK_SAVE_AS},
{"/文件 (_F) /-",NULL,NULL,0,""},
{"/文件 (_F) /退出", NULL, on_menu_activate, "退出", "", GTK_STOCK_QUIT},
{"/编辑 (_E) ", NULL,NULL,0,""},
{"/编辑 (_E) /剪切",NULL,on_menu_activate,"剪切","",GTK_STOCK_CUT},
{"/编辑 (_E) /复制",NULL,on_menu_activate,"复制","",GTK_STOCK_COPY},
{"/编辑 (_E) /粘贴",NULL, on_menu_activate,"粘贴", "", GTK_STOCK_PASTE},
{"/编辑 (_E) /查找",NULL, on_menu_activate,"查找","",GTK_STOCK_FIND},
{"/帮助 (_H) ",NULL,NULL,0,""},
{"/帮助 (_H) /帮助", NULL, on_menu_activate, "帮助", "", GTK_STOCK_HELP},
{"/帮助 (_H) /关于...", NULL, on_menu_activate, "关于", NULL}
};
void on_menu_activate (GtkMenuItem* item, gpointer data)
{
g_print("菜单项");
g_print(" %s ",(gchar*)data);
g_print("被激活n");
}
int main(int argc, char *argv[])
{
GtkWidget* window;
GtkWidget* box;
GtkWidget* menubar;
GtkAccelGroup* accel_group;
GtkItemFactory* item_factory;
gint n=15;
gtk_init(&argc,&argv);
window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window),"添加菜单的快捷方法");
g_signal_connect(G_OBJECT(window),"destroy",
G_CALLBACK(gtk_main_quit),NULL);
accel_group=gtk_accel_group_new();
box=gtk_vbox_new(FALSE,0);
gtk_container_add(GTK_CONTAINER(window),box);
gtk_widget_show(box);
item_factory=gtk_item_factory_new(GTK_TYPE_MENU_BAR,"",accel_group);
gtk_item_factory_create_items(item_factory,n, menu_items,NULL);
gtk_window_add_accel_group(GTK_WINDOW(window),accel_group);
menubar=gtk_item_factory_get_widget(item_factory,"");
gtk_box_pack_start(GTK_BOX(box),menubar,FALSE,FALSE,0);
gtk_widget_show(menubar);
gtk_widget_show(window);
gtk_main();
return FALSE;
}
|
我想这些警告信息是不会影响到程序的正常运行, 除去的方法目前我还未试出来.
你可以将国际化的功能加进去, 这样可能不会出这些警告.
关于国际化,我想哪些出信息也不会影响程序的正常运行.
如有结果,请回复
你可以将国际化的功能加进去, 这样可能不会出这些警告.
关于国际化,我想哪些出信息也不会影响程序的正常运行.
如有结果,请回复
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。