我是GTK和GALDE的新手。我正在制作一个普通的GUI,其中我有一个开始按钮和一个更新按钮,所以如果我点击开始按钮,开始应该显示在文本条目中,相同的更新按钮。我正在使用文本条目及其缓冲区开始和更新。一切都运行良好,但我收到警告
passing argument 1 of ‘gtk_entry_get_buffer’ from incompatible pointer type [enabled by default]
和
assignment from incompatible pointer type [enabled by default]
请帮助消除这些错误。!
以下是我正在使用的代码
GtkBuilder *builder;
GtkWidget *main_window;
GtkWidget *start_button;
GtkWidget *update_button;
GtkWidget *start_entry;
GtkWidget *update_entry;
GtkWidget *start_entry_buffer;
GtkWidget *update_entry_buffer;
void on_start_button_clicked(GtkButton *start_button)
{
gtk_entry_buffer_set_text (start_entry_buffer,"start ",-1); //error
}
void on_update_button_clicked(GtkButton *update_button)
{
gtk_entry_buffer_set_text (update_entry_buffer,"update ",-1);//error
}
int main(int argc, char *argv[])
{
gtk_init (&argc, &argv);
builder = gtk_builder_new();
if(gtk_builder_add_from_file (builder, "example.glade", NULL) == 0)
{
printf("Error Glade File not Found\n");
exit(0);
}
main_window = GTK_WIDGET (gtk_builder_get_object (builder, "main_window"));
start_button = GTK_WIDGET (gtk_builder_get_object (builder, "start_button"));
update_button = GTK_WIDGET (gtk_builder_get_object (builder, "update_button"));
start_entry = GTK_WIDGET (gtk_builder_get_object (builder, "start_entry"));
start_entry_buffer = gtk_entry_get_buffer (start_entry);//error
update_entry = GTK_WIDGET (gtk_builder_get_object (builder, "update_entry"));
update_entry_buffer = gtk_entry_get_buffer (update_entry);//error
gtk_builder_connect_signals(builder, NULL);
g_object_unref (G_OBJECT (builder));
gtk_widget_show (main_window);
gtk_main ();
return 0;
}
感谢!
答案 0 :(得分:1)
您是否注意到GTK_WIDGET(...)
所有gtk_builder_get_object()
电话周围的GTK_ENTRY(...)
广告?将GtkWidget转换为GtkEntry也是一样的想法:将变量包装在{{1}}周围,它应该可以工作。每种GTK +和GLib类型都有其中一种。此外,如果在演员表中使用了错误的变量,使用这些函数强制转换将在运行时为您提供警告。