Re: g_signal_connect isn't working



On Thu, 2005-03-10 at 21:12 -0500, Pier-Luc Charbonneau wrote:
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

[huge snip]

   
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);
[little snip]

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

Don't cry :)

It's quite easy.

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?)

Nope. The bug is in your code.

"key-press-event"
            gboolean    user_function      (GtkWidget *widget,
                                            GdkEventKey *event,
                                            gpointer user_data);

"clicked"   void        user_function      (GtkButton *button,
                                            gpointer user_data);

So in the key_press_even callback you're using the GdkEvenKey value to do the calculation that's all.

Change your key_press_event callback for something like:

gboolean    call_recalculate_psi_consumption (GtkWidget *widget,
                                             GdkEventKey *event,
                                             gpointer user_data)
{
        recalculate_psi_consumption(widget, user_data);
        return FALSE; // I won't manage this signal, let it go ....
}

Thank you and sorry about my english I've been coding for so long my
brain is dead,

Your english is quite good, at least much better than mine.

My recommendation: always have the docs at your side, always check the
signal's callback prototype.

Regards.
-- 
Iago Rubio



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