我是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;
}


谢谢。!

最佳答案

您是否注意到所有GTK_WIDGET(...)调用周围的gtk_builder_get_object()强制转换?将GtkWidget强制转换为GtkEntry是相同的想法:将变量包装在GTK_ENTRY(...)周围,它应该可以工作。每种GTK +和GLib类型都有其中一种。此外,如果在转换中使用了错误的变量,使用这些函数转换将在运行时向您发出警告。

关于c - 如何删除错误“从不兼容的指针类型传递'gtk_entry_get_buffer'的参数1”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29062230/

10-15 16:56