【问题标题】:GTK+ 3.0 and C programmGTK+ 3.0 和 C 程序
【发布时间】:2015-12-20 19:57:29
【问题描述】:

我是 C/C++ 的初级程序员。 ;) 最近在网上找到了有关 GTK 等的资料。我还找到了这个网站:(http://wingtk.sourceforge.net/ishan/sliders.html)。我想运行这段代码,但我的编译器在 231 行(在 sliders.c 中)说这样的话:“GtkWidget 没有名为'parent'的成员”,我不明白,这个程序有什么问题。我试图解决这个问题,但我失败了。

一段代码:

void on_new_activate (GtkMenuItem *menuitem, gpointer user_data)
{

  int rand, x;

  gtk_statusbar_push (GTK_STATUSBAR(statusbar1), 0, "Welcome to sliders");
  move_no=0;

  if (GTK_IS_WIDGET(image) && GTK_IS_WIDGET(image->parent)) //**error here**
  {
    gtk_object_ref (GTK_OBJECT(image));
    gtk_container_remove (GTK_CONTAINER(alignment1), image);
    gtk_container_add (GTK_CONTAINER(alignment1), table1);
    gtk_widget_show (table1);
  }

  for (x=0; x<=14; x++)
  {
    rand = abs(g_rand_int ( g_rand_new () )) % 15;
    if (x!=rand)
       swap_buttons (x, rand);
  }

}

【问题讨论】:

  • 该教程适用于 GTK+ 2。您需要找到其他教程,例如 in the GTK+ documentation。对于那个特定的例子,最好的办法是重写它,这样它就不需要将image 的父级从image 本身中取出,而是直接传递它。
  • @andlabs 可能更糟 - 查看源代码,可能实际上是 GTK+ 1!

标签: c gtk


【解决方案1】:

父容器不再作为成员公开。不要访问image-&gt;parent,而是调用gtk_widget_get_parent(image)

从长远来看,正如@andlabs 所指出的,您最好找到涵盖您正在使用的 GTK+ 版本 3 的教程。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-12-25
    • 2011-12-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多