Re: g_signal_connect() and G_OBJECT
The first argument of `g_signal_connect()` is a gpointer (i.e. a `void*`), so you don't need a cast at all — C will implicitly cast any pointer to `void*`, and from `void*` to any other pointer. Additionally, as you discovered, signals are GTypeInstance features — you can emit signals on anything that inherits from GTypeInstance, not just GObjects. The reason why you see a cast macro is a layer of "extra security": you can check that you're passing the object you meant to be passing, instead of a NULL pointer or some garbage. This "extra security" is mostly cargo-culted through tutorials, so people learn the habit and transmit it. Personally, I find it pointless; internal state should be checked with `g_assert()`, and all cast macros can be compiled away with `G_DISABLE_CAST_CHECKS`, so that buys you almost nothing. Ciao, Emmanuele. On 30 June 2017 at 11:20, Ingo Brückl <i...@wupperonline.de> wrote: > Hi, > > it seems that it was common practice to cast the first argument of > g_signal_connect() to G_OBJECT when I started developing applications with > GTK+ quite a while ago. At least I've learned it that way and am doing it > ever since. > > I repeatedly see usage of g_signal_connect() without that cast which seems > to make sense since "instance" only has to be a gpointer and will be checked > G_TYPE_CHECK_INSTANCE at run time. > > So I'm just curious. Is/was there a reason for the G_OBJECT cast? Was it > necessary back in the days (when GTK+ 2 took over from GTK+ 1)? > > Ingo > ___ > gtk-app-devel-list mailing list > gtk-app-devel-list@gnome.org > https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list -- https://www.bassi.io [@] ebassi [@gmail.com] ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
g_signal_connect() and G_OBJECT
Hi, it seems that it was common practice to cast the first argument of g_signal_connect() to G_OBJECT when I started developing applications with GTK+ quite a while ago. At least I've learned it that way and am doing it ever since. I repeatedly see usage of g_signal_connect() without that cast which seems to make sense since "instance" only has to be a gpointer and will be checked G_TYPE_CHECK_INSTANCE at run time. So I'm just curious. Is/was there a reason for the G_OBJECT cast? Was it necessary back in the days (when GTK+ 2 took over from GTK+ 1)? Ingo ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
noob question: g_signal_connect()
Hi. I've installed the api documentation from the source code for both gtk+ and glib, but I can't seem to find an api description of g_signal_connect(). The examples I usually see are along the lines of code -- g_signal_connect (G_OBJECT (button[0]), draw, G_CALLBACK (draw_callback), NULL); -- Could somebody please explain two things: 1) What is the purpose of the string in the second position in the parameter list? 2) What is the purpose of the fourth parameter slot, with the NULL in it? Can other options go there? -- frigidcode.com indicium.us ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: noob question: g_signal_connect()
On Tue, Mar 06, 2012 at 10:07:16AM -0900, Christopher Howard wrote: Hi. I've installed the api documentation from the source code for both gtk+ and glib, but I can't seem to find an api description of g_signal_connect(). http://developer.gnome.org/gobject/stable/gobject-Signals.html#g-signal-connect -- g_signal_connect (G_OBJECT (button[0]), draw, G_CALLBACK (draw_callback), NULL); -- Could somebody please explain two things: 1) What is the purpose of the string in the second position in the parameter list? That is the signal name – the same as listed in Signals section in the description of each object. 2) What is the purpose of the fourth parameter slot, with the NULL in it? Can other options go there? It is a pointer that the callback function will get as its last argument. You can use it to pass additional data to the callback. Yeti ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
g_signal_connect, structs and my sanity
I'm getting a segfault on the gtkscale callback (when accessing printf(Qs: %i\n, base-sTestOne.a);). Can somebody please tell me what I'm doing wrong. Also, what would be the cleanest way to prototype my struct (struct allStructs) outside of main? Thanks #include sys/types.h #include sys/stat.h #include unistd.h #include string.h #include stdio.h #include config.h #include gtk/gtk.h #include struct.h #include cb.h /* * Standard gettext macros. */ #ifdef ENABLE_NLS # include libintl.h # undef _ # define _(String) dgettext (PACKAGE, String) # ifdef gettext_noop #define N_(String) gettext_noop (String) # else #define N_(String) (String) # endif #else # define textdomain(String) (String) # define gettext(String) (String) # define dgettext(Domain,Message) (Message) # define dcgettext(Domain,Message,Type) (Message) # define bindtextdomain(Domain,Directory) (Domain) # define _(String) (String) # define N_(String) (String) #endif #include callbacks.h /* For testing propose use the local (not installed) glade file */ /* #define GLADE_FILE PACKAGE_DATA_DIR/struct_callback/glade/struct_callback.glade */ #define GLADE_FILE struct_callback.glade void funcScale (GtkWidget *widget, struct allStructs *base) { gdouble value; value = gtk_range_get_value (GTK_RANGE (widget)); printf(Qs: %i\n, value); printf(Qs: %i\n, base-sTestOne.a); } void button_callback (GtkButton *button, struct allStructs *base) { //base-sTestOne.a = 99; printf(Qs: %i\n, base-sTestOne.a); } void button_callback2 (GtkButton *button, struct allStructs *base) { printf(Qs: %i\n, base-sTestOne.a); } int main (int argc, char *argv[]) { struct sOne { int a; }; struct sTwo { int b; }; struct widgets { GtkWidget *window; GtkWidget *button; GtkWidget *hscale; GladeXML *gxml; }; struct allStructs { struct widgets sWidgets; struct sOne sTestOne; struct sTwo sTestTwo; }; struct allStructs base; base.sTestOne.a = 967; #ifdef ENABLE_NLS bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR); bind_textdomain_codeset (GETTEXT_PACKAGE, UTF-8); textdomain (GETTEXT_PACKAGE); #endif gtk_set_locale (); gtk_init (argc, argv); base.sWidgets.gxml = glade_xml_new (GLADE_FILE, NULL, NULL); glade_xml_signal_autoconnect (base.sWidgets.gxml); base.sWidgets.window = glade_xml_get_widget (base.sWidgets.gxml, window); base.sWidgets.button = glade_xml_get_widget (base.sWidgets.gxml, button1); base.sWidgets.hscale = glade_xml_get_widget (base.sWidgets.gxml, hscale1); g_signal_connect (base.sWidgets.button, clicked, G_CALLBACK (button_callback), base); g_signal_connect (base.sWidgets.button, clicked, G_CALLBACK (button_callback2), base); g_signal_connect (base.sWidgets.hscale, change-value, G_CALLBACK (funcScale), base); gtk_widget_show (base.sWidgets.window); gtk_main (); return 0; } -- View this message in context: http://www.nabble.com/g_signal_connect%2C-structs-and-my-sanity-tp20310462p20310462.html Sent from the Gtk+ - Apps Dev mailing list archive at Nabble.com. ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: g_signal_connect, structs and my sanity
I guess you just have the wrong callback function signature for the change-value signal. See http://library.gnome.org/devel/gtk/2.14/GtkRange.html So: void funcScale (GtkWidget *widget, struct allStructs *base) should probably be: void funcScale (GtkRange *range, GtkScrollType scroll, gdouble value, struct allStructs *base) instead. I hope that helps, David void funcScale (GtkWidget *widget, struct allStructs *base) { gdouble value; value = gtk_range_get_value (GTK_RANGE (widget)); printf(Qs: %i\n, value); printf(Qs: %i\n, base-sTestOne.a); } [...] g_signal_connect (base.sWidgets.hscale, change-value, G_CALLBACK (funcScale), base); ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: g_signal_connect, structs and my sanity
Ahgreat thanks for pointing that out. Simple difference between change-value and value-changed. Any feedback on prototyping my struct? Thanks David Munger wrote: I guess you just have the wrong callback function signature for the change-value signal. See http://library.gnome.org/devel/gtk/2.14/GtkRange.html So: void funcScale (GtkWidget *widget, struct allStructs *base) should probably be: void funcScale (GtkRange *range, GtkScrollType scroll, gdouble value, struct allStructs *base) instead. I hope that helps, David void funcScale (GtkWidget *widget, struct allStructs *base) { gdouble value; value = gtk_range_get_value (GTK_RANGE (widget)); printf(Qs: %i\n, value); printf(Qs: %i\n, base-sTestOne.a); } [...] g_signal_connect (base.sWidgets.hscale, change-value, G_CALLBACK (funcScale), base); ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list -- View this message in context: http://www.nabble.com/g_signal_connect%2C-structs-and-my-sanity-tp20310462p20315985.html Sent from the Gtk+ - Apps Dev mailing list archive at Nabble.com. ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Passing Struct to g_signal_connect
I need to pass a struct using g_signal_connect, but the issue I'm having is that I can't alter the elements of the struct within the called function e.g. void on_button2_clicked (struct allStructs *by_ptr) { gtk_label_set_text ((GtkLabel*)by_ptr-widgets.label, whatever); } main { blah blah struct allStructs baseStruct; g_signal_connect (G_OBJECT(baseStruct.widgets.nextButton), clicked, G_CALLBACK (on_button2_clicked), baseStruct); } Any idea's? If I pass this struct to any other function I have no problem performing functions like in the callback. For some reason, I can't in the callback. -- View this message in context: http://www.nabble.com/Passing-Struct-to-g_signal_connect-tp20055372p20055372.html Sent from the Gtk+ - Apps Dev mailing list archive at Nabble.com. ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Passing Struct to g_signal_connect
Hi, you have to make sure that the parameters of your callback function exactly match what's been described for this particular event. In your case your have to check the clicked event for a GtkButton which gives us: void user_function(GtkButton *button, gpointer user_data) So this is how your callback function should look like: void on_button2_clicked(GtkButton *button, struct allStructs *by_ptr) Your struct should be the _second_ parameter and not the first (any only) one your made it. What you did is: You got a pointer to the GtkButton structure of your button and used _that_ as a pointer to your own struct. You are likely messing up the Button structure ... This is one ugly thing with the C bindings and the fact that everything is just casted by this G_CALLBACK() macro. That way the compiler isn't able to check these things and errors like yours happen. And these can be very nasty bugs since they cause people to write to memory they are not supposed to write to. A classic door for hackers ... Till Am Sonntag 19 Oktober 2008 schrieb beginner.c: I need to pass a struct using g_signal_connect, but the issue I'm having is that I can't alter the elements of the struct within the called function e.g. void on_button2_clicked (struct allStructs *by_ptr) { gtk_label_set_text ((GtkLabel*)by_ptr-widgets.label, whatever); } main { blah blah struct allStructs baseStruct; g_signal_connect (G_OBJECT(baseStruct.widgets.nextButton), clicked, G_CALLBACK (on_button2_clicked), baseStruct); } Any idea's? If I pass this struct to any other function I have no problem performing functions like in the callback. For some reason, I can't in the callback. ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Passing Struct to g_signal_connect
Thank you. However, now I'm getting a segfault when trying to access any of the elements of the passed struct. Does it matter that the button to which the signal is attached is actually in the struct I'm passing to the callback? This is what GDB gives me Program received signal SIGSEGV, Segmentation fault. [Switching to Thread 0xb72fa940 (LWP 14464)] 0x08049f16 in on_button2_clicked (button=0x807f418, by_ptr=0x0) at callbacks.h:56 56 printf(Qs: %i\n, by_ptr-globals.Qs); Thanks for your help Till Harbaum / Lists wrote: Hi, you have to make sure that the parameters of your callback function exactly match what's been described for this particular event. In your case your have to check the clicked event for a GtkButton which gives us: void user_function(GtkButton *button, gpointer user_data) So this is how your callback function should look like: void on_button2_clicked(GtkButton *button, struct allStructs *by_ptr) Your struct should be the _second_ parameter and not the first (any only) one your made it. What you did is: You got a pointer to the GtkButton structure of your button and used _that_ as a pointer to your own struct. You are likely messing up the Button structure ... This is one ugly thing with the C bindings and the fact that everything is just casted by this G_CALLBACK() macro. That way the compiler isn't able to check these things and errors like yours happen. And these can be very nasty bugs since they cause people to write to memory they are not supposed to write to. A classic door for hackers ... Till Am Sonntag 19 Oktober 2008 schrieb beginner.c: I need to pass a struct using g_signal_connect, but the issue I'm having is that I can't alter the elements of the struct within the called function e.g. void on_button2_clicked (struct allStructs *by_ptr) { gtk_label_set_text ((GtkLabel*)by_ptr-widgets.label, whatever); } main { blah blah struct allStructs baseStruct; g_signal_connect (G_OBJECT(baseStruct.widgets.nextButton), clicked, G_CALLBACK (on_button2_clicked), baseStruct); } Any idea's? If I pass this struct to any other function I have no problem performing functions like in the callback. For some reason, I can't in the callback. ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list -- View this message in context: http://www.nabble.com/Passing-Struct-to-g_signal_connect-tp20055372p20062941.html Sent from the Gtk+ - Apps Dev mailing list archive at Nabble.com. ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Using g_signal_connect in class
On Tue, Jul 15, 2008 at 6:36 AM, Gabriele Greco [EMAIL PROTECTED] wrote: static void handle_click_cbk(GtkWidget *mywidget_, MyClass *data) { data-handle_click(); } You can't make a callback function intended to be used by C code be inside of the C++ class. It will not be able to find it. Marco, I recommend using the full gtkmm API - this mix of gtk+ and gtkmm will lead to a lot of headaches unless you know where the boundaries of the two are (you can use them together, but typically not in a way you are using it now). Read the excellent docs at http://gtkmm.org/documentation.shtml, specifically the book at http://gtkmm.org/docs/gtkmm-2.4/docs/tutorial/html/index.html dave ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Using g_signal_connect in class
Hello, this is my first post on this mailing list, now i do my request: can i use g_signal_connect in a method of my class, using as c_handler a private function of class? ...and if i can, how i can do ? ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Using g_signal_connect in class
On Tue, Jul 15, 2008 at 12:09 PM, Marco Rocco [EMAIL PROTECTED] wrote: Hello, this is my first post on this mailing list, now i do my request: can i use g_signal_connect in a method of my class, using as c_handler a private function of class? ...and if i can, how i can do ? If you use C++ and plain GTK, supposing you are initializing your callback in the you should do something like this: class MyClass { GtkWidget *mywidget_; static void handle_click_cbk(GtkWidget *mywidget_, MyClass *data) { data-handle_click(); } void handle_click(); // your real callback public: MyClass() { mywidget_ = gtk_button_new(); g_signal_connect(mywidget_, clicked, GCallback(handle_click_cbk), this); } }; -- Bye, Gabry ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Using g_signal_connect in class
Hello, this is my first post on this mailing list, now i do my request: can i use g_signal_connect in a method of my class, using as c_handler a private function of class? ...and if i can, how i can do ? ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Using g_signal_connect in class
Thanks, I have done, but i have the problem of how i get treepath, and how i can pass to callback functions, look my class: class GtkCtree{ private: GtkWidget *treeview; GtkListStore *liststore; Tdata string_to_data(const char *data_string); static void cell_edited_cbk(GtkWidget treeview, GtkCtree *data){ data-cell_edited(); } void cell_edited(GtkCellRendererText *cell, const gchar *path_string, const gchar *new_text, gpointer data){ /* get column */ guint column_number= GPOINTER_TO_UINT(g_object_get_data(G_OBJECT(cell), my_column_num)); /* get row */ GtkTreePath *path = gtk_tree_path_new_from_string(path_string); /* update model */ GtkTreeIter iter; gtk_tree_model_get_iter(GTK_TREE_MODEL(liststore), iter, path); gchar *old_text; gtk_tree_model_get(GTK_TREE_MODEL(liststore), iter, column_number, old_text, -1); gtk_list_store_set(GTK_LIST_STORE(liststore), iter, column_number, new_text, -1); g_free(old_text); } public: GtkCtree(); GtkWidget *get_widget(); void set(GladeXML *xml_file_glade, const char *nome_treeview, int ncolonne, ...); void inserisci_colonna(const char *titolo_colonna, const char *tipo_dato_gtk, int ncolonna); void inserisci_riga(int ncolonne, ...); int get_ID_selezionato(); Tdata get_data_selezionata(); void clear(); void inserisci_colonna_editable(const char *titolo_colonna, const char *tipo_dato_gtk, int ncolonna); }; void GtkCtree::inserisci_colonna_editable(const char *titolo_colonna, const char *tipo_dato_gtk, int ncolonna){ GtkCellRenderer *renderer; GtkTreeViewColumn *colonna; gtk_tree_view_set_model(GTK_TREE_VIEW(treeview), GTK_TREE_MODEL(liststore)); renderer= gtk_cell_renderer_text_new(); colonna= gtk_tree_view_column_new_with_attributes(titolo_colonna, renderer, tipo_dato_gtk, ncolonna, NULL); gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), colonna); g_object_set_data(G_OBJECT(renderer), my_column_num, GUINT_TO_POINTER(1)); g_object_set(renderer, editable, TRUE, NULL); //setta il testo editabile g_signal_connect(renderer, edited, (GCallback) cell_edited_cbk, liststore); } void GtkClist::set(GladeXML *xml_file_glade, const char *nome_treeview, int ncolonne, ...){ treeview= glade_xml_get_widget(xml_file_glade, nome_treeview); va_list arg_pt; va_start(arg_pt, ncolonne); GType *array; array= new GType[ncolonne]; for (int i=0; incolonne; i++) array[i]= va_arg(arg_pt, GType); liststore = gtk_list_store_newv(ncolonne, array); va_end(arg_pt); } void GtkClist::inserisci_riga(int ncolonne, ...){ va_list args; va_start(args, ncolonne); GtkTreeIter newrow; gtk_list_store_append(GTK_LIST_STORE(liststore), newrow); gtk_list_store_set_valist(GTK_LIST_STORE(liststore), newrow, args); va_end(args); } ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
g_signal_connect
For the sake of elegance, which version people like more? 1) g_signal_connect (widget, signal, G_CALLBACK (callback), data); 2) g_signal_connect (G_OBJECT (widget), signal, G_CALLBACK (callback), data); 3) g_signal_connect (GTK_OBJECT (widget), signal, G_CALLBACK (callback), data); Carlos ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: g_signal_connect
Brian J. Tarricone wrote: On Sun, 15 Jun 2008 19:40:22 +0100 Carlos Pereira wrote: For the sake of elegance, which version people like more? 1) g_signal_connect (widget, signal, G_CALLBACK (callback), data); I think this was the intended use -- the first param is of type gpointer so you don't have to use a cast macro like in #2. Most code (but not all) in gtk-demo uses this version... 2) g_signal_connect (G_OBJECT (widget), signal, G_CALLBACK (callback), data); ... but out of (probably stupid) habit, I tend to use this one most of the time... but most of the code in the examples directory, come with the G_OBJECT cast... 3) g_signal_connect (GTK_OBJECT (widget), signal, G_CALLBACK (callback), data); Definitely not this one... *waves arms* GtkObject doesn't exist! *waves arms* Excellent, one less to choose from... I am coming from GTK 1, that's why... ;-) It's interesting anyway, that compiling with -DG_DISABLE_DEPRECATED \ -DGDK_DISABLE_DEPRECATED\ -DGDK_PIXBUF_DISABLE_DEPRECATED \ -DGTK_DISABLE_DEPRECATED activated, no warning is reported, and the signal works just fine, that's why I didn't notice that this was a no no Anyway, GtkObject still exists (I supose mostly because of GtkAdjustment and other old structures?): http://library.gnome.org/devel/gtk/stable/GtkAdjustment.html http://library.gnome.org/devel/gtk/stable/GtkObject.html pkg-config --modversion gtk+-2.0: Gtk 2.12.8 Thanks a lot, Carlos -brian ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
g_signal_connect() Issue
Hi all; I wanted to Know what could be the reason for not being able to connect the select / activate /deselect signal with a widget using g_signal_connect( ) function? I connected a menu widget with the signal select but it fails to respond to it; the menu widget gets rendered ; but takes no siganl via the gtk function g_signal_connect.. Any pointers in this regard will be of great help Thanks Regards sv. ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Using g_signal_connect in an event handler
Hi to all, this is my first experience with GTK+ and my first post here too. I'm currently writing a small application using GtkNotebook. (Not multi-thread or multi-process) My application works in this way: - The main function draws the main GUI and associate some event handlers to some buttons - When one of this button is clicked, the event hanlder associated with it creates a new tab in the GtkNotebook. - Every created tab has an xpm image in the label that allows to close it. To do this I have to connect the event_box containing the xpm image with the close-tab event handler. So I have to use the g_signal_connect function again in the event handler called by the button pressure. The problem is that I do not seem able to pass correctly arguments in this second call. int main(int argc, char *argv[]) { ... gpointer data[5]; ... data[0] = (gpointer) gtk_entry_get_text (GTK_ENTRY (entry)); data[1] = (gpointer) notebook; data[2] = (gpointer) progress_bar; data[3] = (gpointer) stop; data[4] = (gpointer) window; ... g_signal_connect (G_OBJECT (button), clicked, G_CALLBACK (enter_callback), data); ... } gboolean enter_callback(GtkWidget *widget, gpointer *data) { ... g_signal_connect (G_OBJECT (event_box), button-press-event, G_CALLBACK (x_click_callback), data[1]); } gboolean x_click_callback(GtkWidget *event_box, gpointer data) { //Here I get segfault if I try to remove the tab. } I have tried to print out the value of the pointer to the Gtknotebook with a simple g_print(%p, notebook) both in the enter callback and x_click_callback. They are always different. I cannot explain this to myself, because I'm successfully passing arguments and resolving them in the first event handler. Any help will be appreciated. Thank you. ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Using g_signal_connect in an event handler
On Tue, Oct 17, 2006 at 01:51:47PM +0200, Lorenzo Marcon wrote: int main(int argc, char *argv[]) { ... gpointer data[5]; ... data[0] = (gpointer) gtk_entry_get_text (GTK_ENTRY (entry)); data[1] = (gpointer) notebook; data[2] = (gpointer) progress_bar; data[3] = (gpointer) stop; data[4] = (gpointer) window; This is quite cumbersome. Why don't you at least create a struct and pass a pointer to that? You can pass any pointer as the callback data. gboolean enter_callback(GtkWidget *widget, gpointer *data) { ... g_signal_connect (G_OBJECT (event_box), button-press-event, G_CALLBACK (x_click_callback), data[1]); } gboolean x_click_callback(GtkWidget *event_box, gpointer data) { //Here I get segfault if I try to remove the tab. } Because the prototype of the signal handler is different, it gets the event as the second argument. See http://developer.gnome.org/doc/API/2.0/gtk/GtkWidget.html#GtkWidget-button-press-event Yeti -- Whatever. ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Using g_signal_connect in an event handler
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 10/17/2006 5:17 AM, David Ne?as (Yeti) wrote: On Tue, Oct 17, 2006 at 01:51:47PM +0200, Lorenzo Marcon wrote: int main(int argc, char *argv[]) { ... gpointer data[5]; ... data[0] = (gpointer) gtk_entry_get_text (GTK_ENTRY (entry)); data[1] = (gpointer) notebook; data[2] = (gpointer) progress_bar; data[3] = (gpointer) stop; data[4] = (gpointer) window; This is quite cumbersome. Why don't you at least create a struct and pass a pointer to that? You can pass any pointer as the callback data. Not to mention the fact that 'data' is allocated on the stack and ceases to exist after this function exits, so the pointer you pass to g_signal_connect() will be garbage later. Not only should you use a struct for convenience as David suggests, but you need to allocate the struct on the heap (via g_malloc() or g_new(), etc.). -brian -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.2.2 (MingW32) iD8DBQFFNRq36XyW6VEeAnsRAm1wAKC1zkBA7NeFbLT8En9Ur/4S2YPFlwCg3C0E MVoNTChGloKk93C+STNVE+M= =Dk2B -END PGP SIGNATURE- ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Using g_signal_connect in an event handler
On Tue, Oct 17, 2006 at 11:02:32AM -0700, Brian J. Tarricone wrote: On 10/17/2006 5:17 AM, David Ne?as (Yeti) wrote: On Tue, Oct 17, 2006 at 01:51:47PM +0200, Lorenzo Marcon wrote: int main(int argc, char *argv[]) { ... This is quite cumbersome... Not to mention the fact that 'data' is allocated on the stack and ceases to exist after this function exits, so the pointer you pass to g_signal_connect() will be garbage later. Not only should you use a struct for convenience as David suggests, but you need to allocate the struct on the heap (via g_malloc() or g_new(), etc.). I was about to write this too, then I realized the function is main(). So in this particular case the code is probably correct though weird. Anyway, it never hurts to warn of this problem... Yeti -- Whatever. ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: can't ercieve data passed to g_signal_connect
interface.h . . . GtkEventBox **eventt; . . . . interface.c GtkWidget* create_window1 (void) { . . . . . eventt = g_new0 (GtkWidget * , tab_count); . . . for (iter = 1 ; iter = tab_count ; iter++) { . . . . eventt[iter]=GTK_EVENT_BOX(gtk_event_box_new());// create the event box . . . . . data1 = g_strdup_printf( %d ,iter) ; g_print(\n at signal connect string -- %s ,data1); g_signal_connect ((gpointer)eventt[iter],leave_notify_event, G_CALLBACK (mouse_leave1),data1); g_signal_connect ((gpointer)eventt[iter],button_press_event, G_CALLBACK (tab_click1), data1); g_signal_connect ((gpointer)eventt[iter],enter_notify_event, G_CALLBACK (tab_mouse_enter1) , data1); ... } } void tab_click1(GtkWidget *widget,gchar* data1) { gchar *data_1 = (gchar*)data1; unsigned long int val = strtol(data1,NULL,10) ; g_print(%s data1\n,data1); g_print(%d val1\n,val); tab_modifier(1) ; } actually what i am doing is this: i have declared an array of GtkWidget for Eventboxes since i get the number at run time from a database in tab_count (using sqlite3 as database) now i want to connect their signals to the same function as i don't know the number at the design time so can't give that many functions and respective statements the data passe through the signal handler will diferentiate the id of the event box that generated the event. also same function can handle the multiple connect from various controls as it works well in case of first connect here which is used to change the mouse over cursor i never recieve the argument that i send. - Switch an email account to Yahoo! Mail, you could win FIFA World Cup tickets. ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: can't ercieve data passed to g_signal_connect
On 4/21/06, rachit goel [EMAIL PROTECTED] wrote: g_signal_connect ((gpointer)eventt[iter],button_press_event, G_CALLBACK (tab_click1), data1); void tab_click1(GtkWidget *widget,gchar* data1) You have the type of your callback wrong: http://developer.gnome.org/doc/API/2.0/gtk/GtkWidget.html#GtkWidget-button-press-event Try gboolean user_function(GtkWidget *widget, GdkEventButton *event, gpointer user_data) Also you probably have a memory leak there, though maybe it's not important. ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: can't ercieve data passed to g_signal_connect
On Fri, Apr 21, 2006 at 12:45:35PM +0100, rachit goel wrote: g_signal_connect ((gpointer)eventt[iter],leave_notify_event, G_CALLBACK (mouse_leave1),data1); g_signal_connect ((gpointer)eventt[iter],button_press_event, G_CALLBACK (tab_click1), data1); g_signal_connect ((gpointer)eventt[iter],enter_notify_event, G_CALLBACK (tab_mouse_enter1) , data1); ... void tab_click1(GtkWidget *widget,gchar* data1) ... Have a look at the prototypes of *-event callbacks. The second argument is the event, user_data is always the last argument. Yeti -- That's enough. ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
re:re:Re: can't ercieve data passed to g_signal_connect
thanks guys i was mistaken in my assumption about omitting the arguments well thanks anyways that solved the probs Send instant messages to your online friends http://uk.messenger.yahoo.com ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
can't ercieve data passed to g_signal_connect
hi, i am having a problem i just can't recieve the data passed to signal handler using g_signal_connect() . it always gets messed up. plz its rather critical for me at this stage any help will be appreciated also i am using gtk-2.6.7 on fc4-i386 - Switch an email account to Yahoo! Mail, you could win FIFA World Cup tickets. ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: can't ercieve data passed to g_signal_connect
On Thu, Apr 20, 2006 at 08:25:57PM +0100, rachit goel wrote: i am having a problem You have the problem... i just can't recieve the data passed to signal handler using g_signal_connect() . it always gets messed up. ...you did not post enough information. What's your code? Yeti -- That's enough. ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Tell me about difference between g_signal_connect and g_signal_connect_after
In reference, g_signal_connect : The handler will be called before the default handler of the signal. g_signal_connect_after : The handler will be called after the default handler of the signal. But, I don't know why is different g_signal_connect and g_signal_connect_after. Where is example about difference or explain them? ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Tell me about difference between g_signal_connect and g_signal_connect_after
Cool Guy wrote: In reference, g_signal_connect : The handler will be called before the default handler of the signal. g_signal_connect_after : The handler will be called after the default handler of the signal. But, I don't know why is different g_signal_connect and g_signal_connect_after. Where is example about difference or explain them? g_signal_connect_after will let you run your user handler after the class's default handler; why is this usefull ? Say I have an object that emits an initialize signal in which its class handler does the work, you probably want your handler to run after the class handler so that you can use the already initialized object in your function. I think normally you dont have to use this method because signals of that nature are usually installed with G_SIGNAL_RUN_FIRST which; if I'm not mistaken means that it's default handler will be called before user handlers anyway. Cheers, -Tristan ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
strangeness of g_signal_connect
Hi, In my app I have the following: g_signal_connect ((gpointer) AddFile_button, clicked, G_CALLBACK (on_add_files_activate), dummy); I have noticed that if the function on_add_files_activate is declared with only one parameter, gpointer data , I never receive the word dummy. Instead if the same function is declared with two parameters: void on_add_files_activate ( GtkWidget *useless , gpointer data); I can successfull print the value dummy pointed by data. Could gtk developers explain this strange behaviour please ? -- Colossus Cpsed, a Linux OpenGL 3D scene editor http://cpsed.sourceforge.net/ ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: strangeness of g_signal_connect
On Mon, Jul 25, 2005 at 09:18:57AM -0700, Colossus wrote: g_signal_connect ((gpointer) AddFile_button, clicked, G_CALLBACK (on_add_files_activate), dummy); I have noticed that if the function on_add_files_activate is declared with only one parameter, gpointer data , I never receive the word dummy. Instead if the same function is declared with two parameters: void on_add_files_activate ( GtkWidget *useless , gpointer data); I can successfull print the value dummy pointed by data. Could gtk developers explain this strange behaviour please ? There's nothing strange about this behaviour. The first argument of signal handlers is alwasy the object that emitted the signal, user_data is the last. If you want user_data as the first argument, use g_signal_connect_swapped(). Please read the Gtk+ tutorial. The fact C functions may be called with more arguments than declared (though it's still error in ANSI C if you do that without typecast) is just a side-effect of C calling convention. Yeti -- A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing? A: Top-posting. Q: What is the most annoying thing on usenet and in e-mail? ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: strangeness of g_signal_connect
Colossus [EMAIL PROTECTED] writes: In my app I have the following: g_signal_connect ((gpointer) AddFile_button, clicked, G_CALLBACK (on_add_files_activate), dummy); I normally write the above call like this: g_signal_connect( G_OBJECT(AddFile_button), clicked, G_CALLBACK(on_add_files_activate), dummy); Are both correct? Which is the preferred way to do it? I have noticed that if the function on_add_files_activate is declared with only one parameter, gpointer data , I never receive the word dummy. Instead if the same function is declared with two parameters: void on_add_files_activate ( GtkWidget *useless , gpointer data); I can successfull print the value dummy pointed by data. Could gtk developers explain this strange behaviour please ? The actual parameters of the callback function is determined by the event and the widget handling the event. Here you are handling the clicked event for a GtkButton. And for this event, the prototype of the callback handler is void user_function(GtkButton *button, gpointer user_data); http://developer.gnome.org/doc/API/2.0/gtk/GtkButton.html#GtkButton-clicked You can use it or not, but you cannot change their order or add more arguments. Maybe others can add more information on this. Rgds, anna -- Open Movie: Not only will the project be realized with Open Source/Free Software, but also the resulting movie will be published under an open public license. This makes it an exciting premiere as first ever Open Movie project! [ http://orange.blender.org ] ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: strangeness of g_signal_connect
Annamalai Gurusami wrote: g_signal_connect( G_OBJECT(AddFile_button), clicked, G_CALLBACK(on_add_files_activate), dummy); The actual parameters of the callback function is determined by the event and the widget handling the event. Here you are handling the clicked event for a GtkButton. And for this event, the prototype of the callback handler is I just tried to replace gpointer with G_OBJECT but nothing to do, the value dummy is never received by the function. I must use two parameters and get rid of the first one to receive the value dummy. -- Colossus Cpsed, a Linux OpenGL 3D scene editor http://cpsed.sourceforge.net/ ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: strangeness of g_signal_connect
Colossus [EMAIL PROTECTED] writes: Annamalai Gurusami wrote: g_signal_connect( G_OBJECT(AddFile_button), clicked, G_CALLBACK(on_add_files_activate), dummy); The actual parameters of the callback function is determined by the event and the widget handling the event. Here you are handling the clicked event for a GtkButton. And for this event, the prototype of the callback handler is I just tried to replace gpointer with G_OBJECT but nothing to do, the value dummy is never received by the function. I must use two parameters and get rid of the first one to receive the value dummy. You took two *separate* comments, joined it together, and now complaining that my suggestion didn't work!! Funny! :-D What I was suggesting is that g_signal_connect( G_OBJECT(AddFile_button), clicked, G_CALLBACK(on_add_files_activate), dummy); is better than g_signal_connect( (gpointer)AddFile_button, clicked, G_CALLBACK(on_add_files_activate), dummy); because G_OBJECT does some type checking. This has nothing to do with the semantics of callback functions. Rgds, anna -- Open Movie: Not only will the project be realized with Open Source/Free Software, but also the resulting movie will be published under an open public license. This makes it an exciting premiere as first ever Open Movie project! [ http://orange.blender.org ] ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
variables in g_signal_connect
When connecting signals to methods is is possible to add additional variables to the signals and if so in which way. Furthermore, the 4th variable, data, does it have to be a gpointer? I have the following function defined as: Horizontal_Zoom_In_clicked(GtkWidget *widget, int gt) and the signal connection as: g_signal_connect ((gpointer) Horizontal_Zoom_In, clicked, G_CALLBACK (Horizontal_Zoom_In_clicked), graph_type); where graph_type is an int. as a result I get a warning: passing argument 4 of 'g_signal_connect_data' makes pointer from integer without a cast now I was wondering if it is possible to pass a variable into the Horizontal_Zoom_In_clicked method without it being a gpointer but an int instead and if so how this is to be done. Thanks a lot, Michal ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: variables in g_signal_connect
You should use the GINT_TO_POINTER() macro on your variable. Then use GPOINTER_TO_INT() to extract the int back out of the pointer. See this: http://developer.gnome.org/doc/API/2.0/glib/glib-Type-Conversion-Macros.html#GINT-TO-POINTER:CAPS This method will work, but only for integers (since pointers are really just integers that store a memory address). If you want to pass other variable types (or even multiple variables), just create a struct with everything you need, make a pointer that points to it, and pass that to your signal handler. Cheers, Chris Anderson On 7/14/05, Michal Porzuczek [EMAIL PROTECTED] wrote: When connecting signals to methods is is possible to add additional variables to the signals and if so in which way. Furthermore, the 4th variable, data, does it have to be a gpointer? I have the following function defined as: Horizontal_Zoom_In_clicked(GtkWidget *widget, int gt) and the signal connection as: g_signal_connect ((gpointer) Horizontal_Zoom_In, clicked, G_CALLBACK (Horizontal_Zoom_In_clicked), graph_type); where graph_type is an int. as a result I get a warning: passing argument 4 of 'g_signal_connect_data' makes pointer from integer without a cast now I was wondering if it is possible to pass a variable into the Horizontal_Zoom_In_clicked method without it being a gpointer but an int instead and if so how this is to be done. Thanks a lot, Michal ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
RE: variables in g_signal_connect
use GINT_TO_POINTER: Horizontal_Zoom_In_clicked(GtkWidget *widget, gpointer gt) g_signal_connect ((gpointer) Horizontal_Zoom_In, clicked, G_CALLBACK (Horizontal_Zoom_In_clicked), GINT_TO_POINTER(graph_type)); and GPOINTER_TO_INT(gt) in the callback to get the int value from the pointer. see also http://developer.gnome.org/doc/API/2.0/glib/glib-Type-Conversion-Macros.html gyozo -- When you're not looking at it, this fortune is written in FORTRAN. ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: g_signal_connect: what are the detailed_signal ?
Hi ! You can see this for each widget in its GTK+ source. eg: GtkButton() supports signals like clicked etc, which can be found by looking in its header files, gtkbutton.h or in the source gtkbutton.c. /* GtkButton.h */ struct _GtkButtonClass { GtkBinClassparent_class; void (* pressed) (GtkButton *button); void (* released) (GtkButton *button); void (* clicked) (GtkButton *button); void (* enter)(GtkButton *button); void (* leave)(GtkButton *button); void (* activate) (GtkButton *button); /* Padding for future expansion */ void (*_gtk_reserved1) (void); void (*_gtk_reserved2) (void); void (*_gtk_reserved3) (void); void (*_gtk_reserved4) (void); }; Moreover each widget inherits from its parent the signals also. eg: GtkButton widget inherits from GtkBin, which inherits from GtkContainer: so also signals like add,remove are available for g_signal_connect for the GtkWidget types. /* from GtkContainer.h */ struct _GtkContainerClass { GtkWidgetClass parent_class; void(*add)(GtkContainer*container, GtkWidget *widget); void(*remove) (GtkContainer*container, GtkWidget *widget); void(*check_resize) (GtkContainer*container); void(*forall) (GtkContainer*container, gboolean include_internals, GtkCallback callback, gpointer callback_data); void(*set_focus_child)(GtkContainer *container, GtkWidget *widget); GType (*child_type) (GtkContainer*container); gchar* (*composite_name) (GtkContainer*container, GtkWidget *child); void(*set_child_property) (GtkContainer *container, GtkWidget *child, guintproperty_id, const GValue*value, GParamSpec *pspec); void(*get_child_property) (GtkContainer *container, GtkWidget *child, guintproperty_id, GValue *value, GParamSpec *pspec); /* Padding for future expansion */ void (*_gtk_reserved1) (void); void (*_gtk_reserved2) (void); void (*_gtk_reserved3) (void); void (*_gtk_reserved4) (void); }; Cheers Muthu --- Colossus [EMAIL PROTECTED] wrote: Hi, I need to know what are is the signal strings to give to g_signal_connect() but I didn't find any specs of them in doc. Possible ? -- Colossus Cpsed, a Linux OpenGL 3D scene editor http://cpsed.sourceforge.net/ ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list __ Do you Yahoo!? Yahoo! Mail - Helps protect you from nasty viruses. http://promotions.yahoo.com/new_mail ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
g_signal_connect: what are the detailed_signal ?
Hi, I need to know what are is the signal strings to give to g_signal_connect() but I didn't find any specs of them in doc. Possible ? -- Colossus Cpsed, a Linux OpenGL 3D scene editor http://cpsed.sourceforge.net/ ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
g_signal_connect arguments
Hi all, I am new to GTK programming, and I've got a very simple question about callbacks. In the application interface that I am encoding the next function brings up a window containing several GtkEntries and a GtkCheckButton to gather the options chosen by the user: void menu_qdisc(){ .. GtkWidget *isRoot; GtkWidget *entry1; GtkWidget *entry2; isRoot = gtk_check_button_new_with_label (root qdisc); entry1 = gtk_entry_new(); entry2 = gtk_entry_new(); .. g_signal_connect(G_OBJECT (button), clicked, G_CALLBACK (callback_create), ???); The problem is that I don't know how to define the signal_connect function as all the examples that I've found only pass one widget parameter to the callback. Should I pass the window containing all the widgets as an argument? void callbackcreate(GtkWidget *boton, gpointer data){ .. } And what is the way to read the user info from the widgets in the callback function? Thank you very much for your help, and sorry if the topic appears to be too simple. Regards, Fran ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
g_signal_connect
Little trouble here =) the g_signal_connect works like what? g_signal_connect(GTK_WIDGET(widget), signal(clicked), G_CALLBACK(Function), (gpointer) Data); but the callbacks functions have the GtkWidget *Widget as a 1st parameter, and... well, i simply don't get it. =) Does anyone cares to explain to this little noob the arts and secrets of the g_signal_connect? ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
g_signal_connect isn't working
Hi, I'm trying to write my first gtk+ app and this snippet isn't working (tried on 2 different computer and I tried to upgrade to the latest gtk+) When pressing a key in the entry: where is psi : 134520912 where is data: 135602024 psistart *psi : 514 psistart *data: 8 When pushing the button: where is psi : 134520912 where is data: 134520912 psistart *psi : 514 psistart *data: 514 here is the code: #include gtk/gtk.h typedef struct{ int psistart; int psiend; int psidiff; }PSI; PSI *psi; static gboolean delete_event (GtkWidget *widget, GdkEvent *event, gpointer data) { gtk_main_quit(); return FALSE; } static gboolean recalculate_psi_consumption(GtkWidget *widget, gpointer data) { PSI *psi2; psi2 = (PSI *) data; g_print(where is psi : %i\n,psi); g_print(where is data: %i\n,(PSI *)data); g_print(psistart *psi : %i\n,((PSI*)psi)-psistart); g_print(psistart *data: %i\n\n\n,((PSI*)data)-psistart); } int main(int argc, char *argv[]) { psi = g_new(PSI,1); psi-psistart=514; gtk_init (argc, argv); GtkWidget *window; GtkWidget *button; GtkWidget *start; GtkWidget *table; window = gtk_window_new (GTK_WINDOW_TOPLEVEL); g_signal_connect (G_OBJECT (window), delete_event,G_CALLBACK (delete_event), NULL); button = gtk_button_new_with_label(Hi!); table = gtk_table_new (2, 1, FALSE); gtk_container_add(GTK_CONTAINER(window),table); gtk_table_attach_defaults(GTK_TABLE(table),button,0,1,0,1); gtk_table_attach_defaults(GTK_TABLE(table),start = gtk_entry_new(),1,2,0,1); g_signal_connect(G_OBJECT(start),key_press_event,G_CALLBACK(recalculate_psi_consumption),(gpointer)psi); g_signal_connect(G_OBJECT(button),clicked,G_CALLBACK(recalculate_psi_consumption),(gpointer)psi); gtk_widget_show_all (window); gtk_main (); return 0; } I'm working on this bug for 9 hours I can't see why the button and the entry are not showing the same g_print result... Crying or Very sad My last resort is that it is a bug in gtk+ but since I'm new to gtk+ I don't think so... (Am I wrong?) Thank you and sorry about my english I've been coding for so long my brain is dead, IcyWolf ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: g_signal_connect isn't working
Pier-Luc Charbonneau wrote: static gboolean recalculate_psi_consumption(GtkWidget *widget, gpointer data) This is your callback declaration. It takes 2 parameters. g_signal_connect(G_OBJECT(start),key_press_event,G_CALLBACK(recalculate_psi_consumption),(gpointer)psi); key-press-event signal handler must take 3 parameters, look at: http://developer.gnome.org/doc/API/2.0/gtk/GtkWidget.html#GtkWidget-key-press-event You have to make a wrapper over your callback, smth like: static gboolean wrapper (GtkWidget *widget, GdkEvent *event, gpointer data) { recalculate_psi_consumtion (widget, data); return FALSE; /* or TRUE if you dont want other callbacks to pop-up */ } g_signal_connect(G_OBJECT(button),clicked,G_CALLBACK(recalculate_psi_consumption),(gpointer)psi); This one is Ok. clicked callback takes 2 parameters, like your callback. Keep in mind that all *-event callbacks want three parameters: widget, event structure and user data. Even more - they should return gboolean value: TRUE means that event was processed and FALSE means that event wasn't processed and all other callbacks will be called. Olexiy ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list