c - Critical error when trying to retrieve text value of GTKEntry -


i'm learning basics of gtk school project , trying create basic program prints value of text entry changed. whilst getting output of kind, critical error says :

gtk-critical **: gtk_entry_get_text: assertion 'gtk_is_entry (entry)' failed text : (null) 

my code follows :

#include<gtk/gtk.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include "salesbase.h" #include <sqlite3.h> #include <unistd.h>  static void change_text(gtkwidget *widget, gtkentry *data){     const char* output = gtk_entry_get_text(data);     printf("the text : %s\n", output); }  int main(int argc, char *argv[]){     gtkbuilder *builder;     gtk_init(&argc, &argv);     gobject *window;     gtkentry *input;      builder = gtk_builder_new();     gtk_builder_add_from_file(builder, "ui/main.ui", null);      window = gtk_builder_get_object(builder, "mainwindow");     g_signal_connect (window, "destroy", g_callback(gtk_main_quit), null);     input = gtk_entry(gtk_builder_get_object(builder, "test_entry"));     g_signal_connect(input, "changed", g_callback(change_text), &input);        gtk_main();      return 0; } 

fourth argument g_signal_connect gpointer, alias void *, is pointer. input pointer, if want pass it, can pass directly:

g_signal_connect(input, "changed", g_callback(change_text), input); 

passing &input has 2 problems: passes pointer-to-pointer (gtkentry**) function expecting pointer (gtkentry*), fails; , input local variable, store pointer local variable may go out of scope (in example that's no problem, since input outlives main loop).

however, connect signal input, receiver of signal default passed first argument of callback, don't have carry carry around, can simplify code to:

g_signal_connect(input, "changed", g_callback(change_text), null); ... static void change_text(gtkwidget *widget, gpointer data){     const char* output = gtk_entry_get_text(gtk_entry(widget));     printf("the text : %s\n", output); } 

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -