QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 1228|回复: 9

gtk_widget_show_all(window)错误

[复制链接]
发表于 2004-10-21 09:52:27 | 显示全部楼层 |阅读模式
我编了一个小程序,编译运行时出错:
GLib-GObject-CRITICAL **: gtype.c:1875: initialization assertion failed, use g_type_init() prior to this function

GLib-GObject-CRITICAL **: file gobject.c: line 615 (g_object_new): assertion `G_TYPE_IS_OBJECT (object_type)' failed
段错误

我的程序大体时这样的:
int
main (int argc, char *argv[])
{
...
create_window ();/调用创建创口的函数
...
}
GtkWidget*
create_window (void)
{
......
gtk_widget_show_all(window);
}
    我用xxgdb调试设置断点,单步执行,运行到gtk_widget_show_all(window)这里时就出现上面的错误。
    都好几天了,郁闷啦,求助各位啦!谢谢
发表于 2004-10-21 10:20:02 | 显示全部楼层
把代码全部贴出来. 连你的 window 在什么地方定义地都不知道, 看不出问题.
回复

使用道具 举报

发表于 2004-10-21 13:50:44 | 显示全部楼层
贴出create_window中与window相关代码
回复

使用道具 举报

 楼主| 发表于 2004-10-22 09:37:27 | 显示全部楼层
谢谢两位:
GtkWidget *create_window (void)
{
  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title (GTK_WINDOW (window), "wwww");
  gtk_signal_connect (GTK_OBJECT (window), "destroy",GTK_SIGNAL_FUNC (my_quit), NULL);
  gtk_widget_set_usize (window, 165, 600);
  gtk_container_set_border_width (GTK_CONTAINER (window), 2);

  vbox = gtk_vbox_new (FALSE, 0);
  gtk_widget_show (vbox);
  gtk_container_add (GTK_CONTAINER (window), vbox);
  gtk_container_set_border_width (GTK_CONTAINER (vbox), 2);

  scrolled_win = gtk_scrolled_window_new (NULL, NULL);
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win),
                                  GTK_POLICY_AUTOMATIC, K_POLICY_AUTOMATIC);
  gtk_box_pack_start (GTK_BOX (vbox), scrolled_win, TRUE, TRUE, 0);
  gtk_widget_set_usize (scrolled_win, 150, 300);
  gtk_widget_show (scrolled_win);

  tree = gtk_tree_new ();
  gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_win), tree);
/* select mode  */
  gtk_tree_set_selection_mode (GTK_TREE (tree), GTK_SELECTION_SINGLE);
  gtk_widget_show (tree);
  
  /* 日历构件  */
  frame = gtk_frame_new ("Calendar");
  gtk_widget_show (frame);
  gtk_box_pack_start (GTK_BOX (vbox), frame, TRUE, TRUE, 0);
  gtk_widget_set_usize (frame, 165, 130);
  gtk_container_set_border_width (GTK_CONTAINER (frame), 2);
  calendar = gtk_calendar_new ();

  table = gtk_table_new (2, 3, FALSE);
  gtk_widget_show (table);
  gtk_box_pack_start (GTK_BOX (vbox), table, TRUE, TRUE, 0);
  gtk_widget_set_usize (table, 165, 50);
  gtk_table_set_row_spacings (GTK_TABLE (table), 2);
  gtk_table_set_col_spacings (GTK_TABLE (table), 4);
  gtk_container_set_border_width (GTK_CONTAINER (table), 2);

然后table里面是几个按钮:
  。。。。。。
  gtk_widget_show_all (window);
}

nt main (int argc, char *argv[])
{
  gtk_init (&argc, &argv);
  create_window ();
  gtk_main ();
  return 0;
}

大体上就这些了!谢谢了
回复

使用道具 举报

发表于 2004-10-22 11:45:48 | 显示全部楼层
你贴出的代码都没问题
如果没什么保密就全贴出来
回复

使用道具 举报

 楼主| 发表于 2004-10-22 18:06:39 | 显示全部楼层
GtkWidget *create_window (void)
{
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window), "wwww");
gtk_signal_connect (GTK_OBJECT (window), "destroy",GTK_SIGNAL_FUNC (my_quit), NULL);
gtk_widget_set_usize (window, 165, 600);
gtk_container_set_border_width (GTK_CONTAINER (window), 2);

vbox = gtk_vbox_new (FALSE, 0);
gtk_widget_show (vbox);
gtk_container_add (GTK_CONTAINER (window), vbox);
gtk_container_set_border_width (GTK_CONTAINER (vbox), 2);

scrolled_win = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win),
GTK_POLICY_AUTOMATIC, K_POLICY_AUTOMATIC);
gtk_box_pack_start (GTK_BOX (vbox), scrolled_win, TRUE, TRUE, 0);
gtk_widget_set_usize (scrolled_win, 150, 300);
gtk_widget_show (scrolled_win);

tree = gtk_tree_new ();
gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_win), tree);
/* select mode */
gtk_tree_set_selection_mode (GTK_TREE (tree), GTK_SELECTION_SINGLE);
gtk_widget_show (tree);

/* 日历构件 */
frame = gtk_frame_new ("Calendar");
gtk_widget_show (frame);
gtk_box_pack_start (GTK_BOX (vbox), frame, TRUE, TRUE, 0);
gtk_widget_set_usize (frame, 165, 130);
gtk_container_set_border_width (GTK_CONTAINER (frame), 2);
calendar = gtk_calendar_new ();

table = gtk_table_new (2, 3, FALSE);
gtk_widget_show (table);
gtk_box_pack_start (GTK_BOX (vbox), table, TRUE, TRUE, 0);
gtk_widget_set_usize (table, 165, 50);
gtk_table_set_row_spacings (GTK_TABLE (table), 2);
gtk_table_set_col_spacings (GTK_TABLE (table), 4);
gtk_container_set_border_width (GTK_CONTAINER (table), 2);

//然后table里面是几个按钮:
button1 = gtk_button_new_with_label ("clicked");
gtk_widget_show (button1);
gtk_table_attach (GTK_TABLE (table), button1, 0, 1, 0, 1,
(GtkAttachOptions) (GTK_FILL),
(GtkAttachOptions) (0), 0, 0);
gtk_widget_set_usize (button1, 50, 25);

button2 = gtk_button_new_with_label ("clicked");
gtk_widget_show (button1);
gtk_table_attach (GTK_TABLE (table), button2, 1, 2, 0, 1,
(GtkAttachOptions) (GTK_FILL),
(GtkAttachOptions) (0), 0, 0);
gtk_widget_set_usize (button1, 50, 25);

button3 = gtk_button_new_with_label ("clicked");
gtk_widget_show (button3);
gtk_table_attach (GTK_TABLE (table), button3, 2, 3, 0, 1,
(GtkAttachOptions) (GTK_FILL),
(GtkAttachOptions) (0), 0, 0);
gtk_widget_set_usize (button3, 50, 25);

seek = gtk_adjustment_new (0, 0, 100, 1, 0, 0);
scale = gtk_hscale_new (GTK_ADJUSTMENT (seek));
gtk_object_set_data_full (GTK_OBJECT (window), "scale", scale,
(GtkDestroyNotify) 0);
gtk_scale_set_draw_value (GTK_SCALE (scale), FALSE);
gtk_table_attach(GTK_TABLE(table), scale, 0, 3, 1, 2,
(GtkAttachOptions)(GTK_FILL),
(GtkAttachOptions)(0),0,0);
gtk_widget_show (scale);

gtk_widget_show_all (window);

}

nt main (int argc, char *argv[])
{
gtk_init (&argc, &argv);
create_window ();
gtk_main ();
return 0;
}
没什么保密的。只是嫌麻烦,看了不爽!
我在以前的系统里面能运行的,重装linux就出现这样的问题了!
郁闷,都好几天了!运行就出现上面的问题,调试也是这样!
帮忙分析一下是object错误吗!
回复

使用道具 举报

发表于 2004-10-22 21:40:48 | 显示全部楼层
出了K_POLICY_AUTOMATIC应改为GTK_POLICY_AUTOMATIC外没什么问题,运行也正常。
你的那些window,vbox,scrolled_win是在哪里定义的。
回复

使用道具 举报

 楼主| 发表于 2004-10-23 16:29:14 | 显示全部楼层
K_POLICY_AUTOMATIC这个可能是不小心删错了!
window,vbox,scrolled_win都是在creat_window里面定义的!不会错的!,
我以前就可以运行的,真是的,重装系统后就这样!
GLib-GObject-CRITICAL **: gtype.c:1875: initialization assertion failed, use g_type_init() prior to this function
GLib-GObject-CRITICAL **: file gobject.c: line 615 (g_object_new): assertion `G_TYPE_IS_OBJECT (object_type)' failed
斑竹能给说说这两句到底是什么意思吗!
回复

使用道具 举报

发表于 2004-10-23 17:48:06 | 显示全部楼层
应该是指针没初始化。程序本身应该没什么问题,你重新安装一下gtk和glib试试。
回复

使用道具 举报

发表于 2004-10-23 20:39:31 | 显示全部楼层
没有源程序,一条一条的看太花时间。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-11-7 05:23 , Processed in 0.053089 second(s), 16 queries .

© 2021 Powered by Discuz! X3.5.

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