-1

I am new to GTK and GALDE. I am making a normal GUI in which I have one start button and one update button, so that if I click on start button, start should be displayed in text entry and same for the update button.I am using text entry and its buffer for start and update. Everything is running fine but I am getting warning

passing argument 1 of ‘gtk_entry_get_buffer’ from incompatible pointer type [enabled by default] and

assignment from incompatible pointer type [enabled by default]

Please help in removing these errors.!

Below is the code which I am using

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

Thanks.!

user46573544
  • 137
  • 3
  • 4
  • 13
  • 1
    And *where* do you get the errors? On what lines? Please edit your question to show it in the source. – Some programmer dude Mar 15 '15 at 15:16
  • And also please show variable declarations. – Some programmer dude Mar 15 '15 at 15:17
  • You have more problems to think about like, why is `builder` declared as a global variable? is it a flaw in the design? and you probably need a macro like `GTK_BUILDER` to cast the value to the correct type, But I don't know if that is the exact name of the macro, also you didn't post the declaration of `builder` which you really should remove from the global scope. – Iharob Al Asimi Mar 15 '15 at 15:17
  • @JoachimPileborg i have put //error at the line where I am getting error – user46573544 Mar 15 '15 at 15:19
  • @iharob the person's question has nothing to do with GtkBuilder; his use of GtkBuilder is correct. And what harm is it that the GtkBuilder is global? There's no bug there. The problem is that he didn't see that there is a `GTK_ENTRY(...)` for taking a GtkWidget and turning it into a GtkEntry, whereas he used `GTK_WIDGET(...)` to turn the GtkBuilder's GObjects into GtkWidgets. – andlabs Mar 15 '15 at 15:56
  • @andlabs yes you are right.! – user46573544 Mar 17 '15 at 17:11

1 Answers1

1

Did you notice the GTK_WIDGET(...) casts around all your gtk_builder_get_object() calls? It's the same idea for casting a GtkWidget to a GtkEntry: wrap your variable around a GTK_ENTRY(...) and it should work. There's one of these for every GTK+ and GLib type. In addition, using these function casts will give you warnings at runtime if you use the wrong variable in your cast.

andlabs
  • 11,290
  • 1
  • 31
  • 52