LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   GTK+ "cannot convert `GObject*' to `GtkObject*'" error (https://www.linuxquestions.org/questions/programming-9/gtk-cannot-convert-%60gobject%2A-to-%60gtkobject%2A-error-416648/)

Nylex 02-17-2006 04:32 PM

GTK+ "cannot convert `GObject*' to `GtkObject*'" error
 
I'm trying to learn GTK+ and am trying to write a basic program that has a button in a window and doesn't really do anything exciting.

I'm kinda doing this in a C++ way as well, but that shouldn't matter here.

My code (the relevant bit) looks like this:

Code:

int main(int argc, char *argv[])
{
  gtk_init(&argc, &argv);

  GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  g_signal_connect(G_OBJECT(window), "delete_event", G_CALLBACK(delete_event), NULL);
  gtk_container_set_border_width(GTK_CONTAINER(window), 10);

  GtkWidget *button = gtk_button_new_with_label("Hello world!");
  gtk_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(callback), (gpointer)"button");

  gtk_widget_show(button);

  gtk_widget_show(window);

  gtk_main();

  return 0;
}

The problematic line is in bold. When I try to compile with "g++ filename.cc -ofilename `pkg-config --cflags --libs gtk+-2.0", I get the following error:

filename.cc: In function `int main(int, char**)':
filename.cc:18: error: cannot convert `GObject*' to `GtkObject*' for
argument `1' to `gulong gtk_signal_connect_full(GtkObject*, const gchar*,
void (*)(), void (*)(GtkObject*, void*, unsigned int, GtkArg*), void*, void
(*)(void*), int, int)'

I don't understand, because there's a line that looks almost identical to mine here and that compiles fine :confused:. Any ideas?

All help appreciated!

AdaHacker 02-17-2006 04:45 PM

Well, it's been a couple of years since I did any GTK+ programming, but according to the API reference, gtk_signal_connect() takes a GtkObject as the first parameter, whereas you're casting it to a GObject. Plus gtk_signal_connect() has been deprecated, so you shouldn't be using it in the first place. Try changing that to use g_signal_connect() instead and see if that helps.

Nylex 02-17-2006 04:47 PM

Retard (me, not you). I accidentally typed gtk_signal_connect instead of g_signal_connect. Thanks :).


All times are GMT -5. The time now is 01:37 AM.