|
gtk+2.0下生成菜单的错误
int main(int argc, char *argv[])
{
GtkWidget *window;
GtkWidget *vbox;
GtkWidget *hbox;
GtkWidget *button;
GtkWidget *rootmenu;
GtkWidget *menubar;
//生成主窗口并初始化
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
g_signal_connect(G_OBJECT(window), "destroy",
G_CALLBACK(gtk_main_quit), NULL);
gtk_window_set_title(GTK_WINDOW(window), "add menu");
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_container_set_border_width(GTK_CONTAINER(window), 5);
//在主窗口里加入一个垂直盒状容器
vbox = gtk_vbox_new(FALSE, 0);
gtk_container_add(GTK_CONTAINER(window), vbox);
menubar = gtk_menu_bar_new();
gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, FALSE, 5);
menu = gtk_menu_new();
rootmenu = gtk_menu_item_new_with_label("root menu");
menu = gtk_menu_item_new_with_label("menu 1");
gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); //运行到此句出现error!
... ...以下省略
}
错误信息为:
(addmenu:16866): GLib-GObject-WARNING **: invalid cast from `GtkMenuItem' to `GtkMenuShell'
(addmenu:16866): Gtk-CRITICAL **: file gtkmenushell.c: line 353 (gtk_menu_shell_insert): assertion `GTK_IS_MENU_SHELL (menu_shell)' failed
请指点,谢谢。 |
|