3

what should I do to print text from entry when enter is pressed or button is clicked with one function? I am asking because when I am clicking at button I get "(PMAF:3592): Gtk-CRITICAL **: IA__gtk_entry_get_text: assertion 'GTK_IS_ENTRY (entry)' failed (null)"

void print_the_entry(GtkWidget *entry, gpointer user_data)
{
    g_print("%s\n", gtk_entry_get_text(user_data));

}

 //search_entry 
  search_entry = gtk_entry_new();
  g_signal_connect_swapped(G_OBJECT(search_entry), "activate", G_CALLBACK(print_the_entry), (gpointer) search_entry);

  gtk_box_pack_start(GTK_BOX(search_and_do_it_h_box), search_entry, FALSE, FALSE, 0);

  //do_it_button
  do_it_button = gtk_button_new_with_label("Do it!");
  gtk_box_pack_start(GTK_BOX(search_and_do_it_h_box), do_it_button, FALSE, FALSE, 0);
  g_signal_connect_swapped(G_OBJECT(do_it_button), "clicked", G_CALLBACK(print_the_entry), (gpointer) search_entry);
jjpikoov
  • 119
  • 1
  • 11

2 Answers2

1

It seems that you are using a wrong parameter, try:

g_print("%s\n", gtk_entry_get_text(GTK_ENTRY(entry)));
David Ranieri
  • 39,972
  • 7
  • 52
  • 94
  • 1
    Thanks very much, if someone has got warning change "void print_the_entry(GtkWidget *entry, gpointer user_data)" to "void print_the_entry(GtkEntry *entry, gpointer user_data)" – jjpikoov Jan 17 '15 at 10:39
0

You may need this if you want to hold the values(entered in entry text) in a structure of arrays or single array.

gtk_entry_set_text(entry1, detail[i].Name);

where "detail" is a structure variable and "Name" is a member array of the structure.

Simply in cases of GUI having entry text if you want to see the values on a button click there.

djgharphalia07
  • 227
  • 3
  • 14