Re: How can I use g_signal_connect() to pass a gponiter parameter



I replaced g_signal_connect_swapped with g_signal_connect and it works fine now.
Thanks a lot!


On Wed, Feb 4, 2009 at 3:41 AM, Jean Bréfort
<jean brefort normalesup org> wrote:
> Le dimanche 01 février 2009 à 10:22 -0800, frantishek a écrit :
>> My code does it just by the book:
>>
>> void setPermission(GtkWidget *window, gpointer p)
>> {
>>       g_print("%s\n", (gchar*) p);
>> }
>>
>> radio1 = gtk_radio_button_new_with_label (NULL, "First");
>> radio2 = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON
>> (radio1), "Second");
>> radio3 = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON
>> (radio1), "Third");
>> g_signal_connect_swapped (G_OBJECT (radio1), "clicked", G_CALLBACK
>> (setPermission), (gpointer) "Clicked 0");





g_signal_connect_swapped (G_OBJECT (radio2), "clicked", G_CALLBACK
>> (setPermission), (gpointer) "Clicked 1");
>> g_signal_connect_swapped (G_OBJECT (radio3), "clicked", G_CALLBACK
>> (setPermission), (gpointer) "Clicked 2");
>>
>> Yet, when I select any of these radio buttons, it prints out some garbage
>> (the same for each button).
>>
>> Any idea why?
>
> You are using g_singal_connect_swapped, so your gpointer becomes the
> first argument of the callback which should be
>
> void setPermission(gpointer p)
> {
>        g_print("%s\n", (gchar*) p);
> }
>
>
>> learning_gtk wrote:
>> >
>> > I hope to use  g_signal_connect() to pass a gchar* parameter like this:
>> >
>> > gchar* radio1= "Radio1"; //it is global variable
>> > gchar* radio2= "Radio2";
>> > gchar* radio3= "Radio3";
>> >
>> > void item_radio_print1(gpointer* data)
>> > {
>> >         g_print("This is the radio %s\n", (gchar *)data);
>> > }
>> >
>> > g_signal_connect(G_OBJECT(item_radio1), "activate",
>> >                      GTK_SIGNAL_FUNC(item_radio_print1),
>> > (gpointer*)radio1);
>> > g_signal_connect(G_OBJECT(item_radio2), "activate",
>> >                      GTK_SIGNAL_FUNC(item_radio_print1),
>> > (gpointer*)radio2);
>> > g_signal_connect(G_OBJECT(item_radio3), "activate",
>> >                      GTK_SIGNAL_FUNC(item_radio_print1),
>> > (gpointer*)radio3);
>> >
>> > But, those strings can not be printed.
>> >
>> > Please help me. Thanks!
>> >
>>
>
>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]