Hi friend, for

Hi friend, for

Hi friend,
for gtk_signal_emit_by_name you should
pass callback's argument list
not callback itself

below i attached my tested sample
code for this fake signal.
When you click button 1
signal handler of button 2 is called.

see below code
/* Sample code from www.gtkhelp.com
* Gtk Help Team
*
*
*
*
*
*
*
*
*
*
*
*
*/

#include
#include

//Button2 callback

void
hello (GtkWidget * button, gpointer data)
{
printf ("hello B2 clicked\n");
}

//Button 1 callback
//this will generate a fake signal for button2
void
b1_clicked (GtkWidget * button, gpointer data)
{
GtkWidget *b = (GtkWidget *) data;
printf ("in b1\n");
//argument list is the arguments given to callback function
gtk_signal_emit_by_name (G_OBJECT (b), "clicked", b, NULL);
}

//main code
main (int argc, char **argv)
{
GtkWidget *button1, *button2, *fixed;
GtkWidget *window;
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size (window, 400, 400);
gtk_window_set_title (GTK_WINDOW (window), "TEST");
fixed = gtk_fixed_new ();
gtk_widget_show (fixed);
gtk_container_add (GTK_CONTAINER (window), fixed);
button1 = gtk_button_new_with_label ("B1");
button2 = gtk_button_new_with_label ("B2");
gtk_fixed_put (fixed, button1, 10, 5);
gtk_fixed_put (fixed, button2, 50, 5);

//button2
g_signal_connect (G_OBJECT (button2), "clicked", G_CALLBACK (hello), NULL);

//button1
g_signal_connect (G_OBJECT (button1), "clicked", G_CALLBACK (b1_clicked),
button2);

gtk_widget_show_all (window);
gtk_main ();
}

Fake a signal By: neocruze (5 replies) Sat, 03/01/2008 - 19:20