【发布时间】: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!