Re: get datas from entries...



TORRI Vincent wrote:
  just one thing : the prototype of a callback of an entry, associated to 
the "activate" signal, is

  void CallBack(GtkEntry *entry, gpointer data)

  then you could try this connection :

  gtk_signal_connect(GTK_OBJECT(entry), "activate", 
GTK_SIGNAL_FUNC(entry_callback), &MainText);

  and the callback :

void entry_callback(GtlWidget *Entry, GtkWidget **widget) {
  GtkWidget *Text;

  Text = widget[0];
  char *str=gtk_entry_get_text(GTK_ENTRY(Entry));
  gtk_insert_text(GTK_TEXT(Text), str);       
  g_print("%s\n", str);
}

Well, thanks for your help, but it seems this callbacks doesn't compile, here's the function:
void entry_callback(GtlWidget *entry, GtkWidget **widget) { /*line 8*/
  GtkWidget *MainText;
  MainText = widget[0];
  char *str=gtk_entry_get_text(GTK_ENTRY(entry));
  gtk_insert_text(GTK_TEXT(MainText), str);     
  g_print("%s\n", str);
}

here's the error:
bash-2.05$ gcc -Wall -o prog prog.c `gtk-config --cflags --libs`
4.c:8: parse error before `*'
4.c: In function `entry_callback':
4.c:10: `widget' undeclared (first use in this function)
4.c:10: (Each undeclared identifier is reported only once
4.c:10: for each function it appears in.)
4.c:11: parse error before `char'
4.c:12: warning: implicit declaration of function `gtk_insert_text'
4.c:12: `str' undeclared (first use in this function)
bash-2.05$

Perhaps it is not the simpliest way to do that, but it should work

2/

And the second function you gave me works great! :)
But one question though:
i got
gchar *text1, *text2, *text3, *text4; /*for the 4 entries*/
text1=gtk_entry_get_text(GTK_ENTRY(Entries[0]));
text2=gtk_entry_get_text(GTK_ENTRY(Entries[1]));
...

but if i want to add text1 to text2 and put the result into an int, how could i do?
gint *text1...etc ?
maybe atoi(text1) ?


 In the function where yours entries and your button are defined : 

  GtkWidget **Entries; /* In fact, the replacement of your 4 entries */
  GtkWidget *Button;

  Entries = g_malloc(4*sizeof(GtkWidget *));
  /*
  ... You set your entries with Entries[0] = etc..
                                Entries[1] = ...
                                Entries[2] = ...
                                Entries[3] = ...
  and Button = ... 
  */

  /* And you connect the following signal to your button */
  gtk_signal_connect(GTK_OBJECT(Button), "clicked", 
(GtkSignalFunc)calculate), Entries);
  ...

The callback should be :
  void calculate(GtkWidget *w, GtkWidget **Entries)
    {
      gchar *text;
   
      /* to get the text of the first entry : */
      text = gtk_entry_get_text(GTK_ENTRY(Entries[0]));
      /* and so on ... */
    }
  
Hope this will help 

Vincent TORRI

thx
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


-- 
TORRI Vincent
Mathematiques Appliquees Bordeaux                                                
Institut de Mathematiques                                                       
Universite Bordeaux 1                                                           
351 cours de la liberation                                                      
33 405 Talence cedex - France                                                   
                                                                                
Tel : 33 (0)5 57 96 21 42                                                       
Fax : 33 (0)5 56 84 26 26                                                       
--




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