Glade3 C 编程按钮
我非常不知道 GTK+Glade3 编程的语法如何。 但现在我正在尝试制作一个简单的程序,当我单击按钮时更改文本
void on_CLICK_clicked (GtkButton *button, gpointer user_data)
{
GtkWidget *text = lookup_widget(GTK_WIDGET(button), "entry1");
gtk_entry_set_text(GTK_WIDGET(text), "Hello");
}
我遇到了这些令人震惊的错误,我不知道如何解决:
函数“lookup_widget”的隐式声明[这也解释了对“lookup_widget”的未定义引用]
从不兼容的指针类型传递 gtk_entry_set_text' 的参数 1
I'm very unaware of how the syntax goes for GTK+Glade3 programming.
But for now I'm trying to experiment and making a simple program that changes text when I click a button
void on_CLICK_clicked (GtkButton *button, gpointer user_data)
{
GtkWidget *text = lookup_widget(GTK_WIDGET(button), "entry1");
gtk_entry_set_text(GTK_WIDGET(text), "Hello");
}
I have these alarming errors that I don't know how to solve:
implicit declaration of function 'lookup_widget' [which also explains the undefined reference to 'lookup_widget']
passing argument 1 of gtk_entry_set_text' from incompatible pointer type
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
lookup_widget()
仅在 Glade 2 的生成代码中使用。 Glade 2 用于生成一个文件support.c
,其中包含该函数和其他函数。这个已经不再使用了。现在,当您在 Glade 3 中连接clicked
信号时,您可以将条目小部件指定为用户数据参数,因此您可以执行以下操作:第二个警告是由您转换
text 到
GtkWidget *
,然后将其传递给需要GtkEntry *
的gtk_entry_set_text()
。正确的语法是GTK_ENTRY(text)
,但您不再需要这样做,因为在我上面编写的代码中已经有一个GtkEntry *
指针。lookup_widget()
was only used in Glade 2's generated code. Glade 2 used to generate a file,support.c
, that contained that function and other ones. This is not used anymore. You can now specify the entry widget as the user data parameter when you connect theclicked
signal in Glade 3, so you can do the following:The second warning was caused by you casting
text
to aGtkWidget *
and then passing it togtk_entry_set_text()
which expects aGtkEntry *
. The proper syntax would have beenGTK_ENTRY(text)
, but you don't need to do that anymore since you already have aGtkEntry *
pointer in the code I wrote above.