GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Fri Dec 19, 2014 6:15 pm

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: problem with g_signal_connect_after and user_data GTK2+
PostPosted: Mon Jan 14, 2013 8:57 am 
Offline
Familiar Face

Joined: Fri Oct 26, 2012 10:49 am
Posts: 38
Hello!
for a GtkEntry I have connected 2 signals: activate and focus-out-event.
I give the adress of a module-global variable into the user_data for the events.
In the callback-function for the "activate"-event, it works, the content of the user_data is OK
But int the callback-function for the "focus-out-event"-event, the content of the user_data contains nothing. The adress in the gpointer seems to be wrong. I don't understand why, because the way to call the function is exactly the same.
Can somebody help me to know why the values in the user_data of the focus-out-event are wrong or undefined?
Thank you in advance
MBoerner

Code:
// set user data
re_local.parNr[re_local.currParNr] = re_local.currParNr;
re_local.userdata[re_local.currParNr].type_of_param = type_of_param;
re_local.userdata[re_local.currParNr].speicher = speicher;
//
bufferValue = gtk_entry_buffer_new (NULL, 0);
spinOrEntry = gtk_entry_new();
g_signal_connect(GTK_ENTRY(spinOrEntry),"activate",G_CALLBACK(cb_valueEdited), &re_local.userdata[re_local.currParNr]);
g_signal_connect_after (GTK_OBJECT (spinOrEntry), "focus-out-event",G_CALLBACK (cb_NameFocusOut),  &re_local.userdata[re_local.currParNr]);
re_local.currParNr++;



definition of user_data
Code:
typedef struct
{
   void *speicher;
   int type_of_param;

}t_user_data;

t_user_data userdata[MAX_CNT_PAR];


My 2 callbacks functions
Code:
static void cb_valueEdited(GtkEntry *entry, gpointer user_data)
{
   int type;
   void* variable;
   char new_text[50];

   type  = ((t_user_data *)user_data)->type_of_param;
   variable = ((t_user_data *)user_data)->speicher;
   strncpy(new_text, gtk_entry_get_text(entry),50);
}

/*
* @param entry : current entry that has been edited
* @param user_data piointer on a structure that contents the adress of the variable to change and the type of the variable
*/
static void cb_NameFocusOut(GtkWidget *entry, gpointer user_data)
{
   int type;
   void* variable;

   char new_text[50];

   type  = ((t_user_data *)user_data)->type_of_param;
   variable = ((t_user_data *)user_data)->speicher;
   strncpy(new_text, gtk_entry_get_text(GTK_ENTRY(entry)),50);

}
);
g_signal_connect_after (GTK_OBJECT (spinOrEntry),


Top
 Profile  
 
 Post subject: Re: problem with g_signal_connect_after and user_data GTK2+
PostPosted: Mon Jan 14, 2013 6:37 pm 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 799
Location: UK
Hello,

You are using the wrong proto-type for the "focus-out-event" signal. The call back function for the signal "focus-out-event" should be defined as :-
Code:
gboolean            user_function                      (GtkWidget *widget,
                                                        GdkEvent  *event,
                                                        gpointer   user_data)
The documentation can be found at http://developer.gnome.org/gtk2/stable/GtkWidget.html#GtkWidget-focus-out-event

_________________
E.


Top
 Profile  
 
 Post subject: Re: problem with g_signal_connect_after and user_data GTK2+
PostPosted: Tue Jan 15, 2013 6:18 am 
Offline
Familiar Face

Joined: Fri Oct 26, 2012 10:49 am
Posts: 38
Thank you!
I'm sorry, I didn't found this documentation.
It is clear.
Tanks a lot.
MBoerner


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot], Google Adsense [Bot] and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group