I am working on a project in gtk, in conjunction with C to create a simple login interface.
In the first part of the login I only validate the fields and print them in the console, this way of sending more than one ENTRY in a callback I did it with double pointers.
'GtkWidget *Datos[2]; Datos[0] = IdEmpleado; Datos[1] = Password; g_signal_connect(G_OBJECT(Btn_Aceptar), "clicked", G_CALLBACK(Validar_Empleado),Datos); '
And in the function I only do this just to be checking a bit how GTK works, since it is my first program in GTK
'void Validar_Empleado(GtkWidget *Btn, gpointer Datos){ GtkWidget **w = (GtkWidget **)Datos; gchar *userName = (gchar *)gtk_entry_get_text(w[0]); //Tenemos almacenado el texto que el usuario tecleo en el entry IdEmpleado gchar *password = (gchar *)gtk_entry_get_text(w[1]); //Tenemos almacenado el texto que el usuario tecleo en el entry Password printf("Numero de empleado... %s \n",userName); printf("Password capturado... %s \n",password); }'
It should be noted that this part works as I expected, however in the function Create_User where I generate a new window to register a user, I try the same procedure of sending the Entry in the form of an array using a double pointer, such as I did it in this function, but in that aprte I fail, I throw error
IA__gtk_entry_get_text: assertion 'GTK_IS_ENTRY (entry)' failed
I've been dealing with a simple pointer, even with a single widget and it gives me the same error, I do not know if it's a screen different from the main one that is in main, I have to change the logic, I would appreciate any form of support, documentation, examples, etc. I enclose the code that I have, I clarify it is not the best nor the most optimal because I am barely knowing the library and I have not formalized the code.
void Crear_Empleado(){ /*Colores definidos de manera global*/ GdkColor Background, color2, red_btn, color_texto;//Definicion de color gtk para color de fondo Background.red= 18 * (65535/255); Background.blue=119 * (65535/255); Background.green= 1 * (65535/255); //Color fondo color2.red = 195 * (65535/255); color2.blue = 195 * (65535/255); color2.green = 195 * (65535/255); //Color etiquetas red_btn.red = 179 * (65535/255); red_btn.blue = 60 * (65535/255); red_btn.green = 60 * (65535/255); //Color btn cerrar GtkWidget *win_NuevoUsuario,*lbl_NumEmpleado,*NumEmpleado,*lbl_Password,*lbl_Password2,*Password,*Password2,*btn_Guardar,*btn_Cancelar,*lbl_admin,*check_admin; GtkWidget *Table; win_NuevoUsuario = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_widget_modify_bg(win_NuevoUsuario, GTK_STATE_NORMAL, &Background); gtk_window_set_title(GTK_WINDOW(win_NuevoUsuario), "Nuevo Empleado"); gtk_window_set_position(GTK_WINDOW(win_NuevoUsuario),GTK_WIN_POS_CENTER_ALWAYS); gtk_window_set_default_size(win_NuevoUsuario,500,500); gtk_window_set_decorated(win_NuevoUsuario,FALSE); gtk_window_set_modal(win_NuevoUsuario,TRUE); //Creamos tabla para organizar los widget Table = gtk_table_new(30,30,FALSE); gtk_table_set_row_spacings(GTK_TABLE(Table), 15); gtk_table_set_col_spacings(GTK_TABLE(Table), 15);//Generar tabla con numero de columnas,filas,spacing,etc //Creamos los wiget y los posicionamos btn_Cancelar = gtk_button_new_with_label("Cancelar[x]"); gtk_widget_modify_bg(btn_Cancelar,GTK_STATE_NORMAL,&red_btn); gtk_widget_modify_bg(btn_Cancelar,GTK_STATE_PRELIGHT,&red_btn); gtk_table_attach_defaults(GTK_TABLE(Table), btn_Cancelar,29 , 30 , 28 , 30); btn_Guardar = gtk_button_new_with_label("Registrar Usuario"); gtk_table_attach_defaults(GTK_TABLE(Table), btn_Guardar ,27 , 29 , 28 , 30); lbl_NumEmpleado = gtk_label_new("Introduza el número de empleado: "); gtk_table_attach_defaults(GTK_TABLE(Table), lbl_NumEmpleado,4,8,6,7); gtk_widget_modify_fg(lbl_NumEmpleado,GTK_STATE_NORMAL,&color2); lbl_Password = gtk_label_new("Introduza su contraseña: "); gtk_table_attach_defaults(GTK_TABLE(Table), lbl_Password,4,5,10,11); gtk_widget_modify_fg(lbl_Password,GTK_STATE_NORMAL,&color2); lbl_Password2 = gtk_label_new("Confirme su contraseña: "); gtk_table_attach_defaults(GTK_TABLE(Table), lbl_Password2,4,5,14,15); gtk_widget_modify_fg(lbl_Password2,GTK_STATE_NORMAL,&color2); NumEmpleado = gtk_entry_new(); gtk_table_attach_defaults(GTK_TABLE(Table),NumEmpleado,12,16,6,7); Password = gtk_entry_new(); gtk_table_attach_defaults(GTK_TABLE(Table),Password,12,16,10,11); Password2 = gtk_entry_new(); gtk_table_attach_defaults(GTK_TABLE(Table),Password2,12,16,14,15); lbl_admin = gtk_label_new("Usuario Administrador: "); gtk_table_attach_defaults(GTK_TABLE(Table),lbl_admin,4,5,19,20); gtk_widget_modify_fg(lbl_admin,GTK_STATE_NORMAL,&color2); check_admin = gtk_check_button_new_with_label("Otorgar permisos de administrador"); gtk_table_attach_defaults(GTK_TABLE(Table),check_admin,13,14,19,20); gtk_widget_modify_fg(check_admin,GTK_STATE_NORMAL,&color2); gtk_container_add(GTK_CONTAINER(win_NuevoUsuario), Table);//Asignamos el container a la ventana gtk_container_set_border_width(GTK_CONTAINER(win_NuevoUsuario), 10); gtk_widget_show_all(win_NuevoUsuario); //Creacion de arreglo de widget para enviar datos GtkWidget *Datos[3]; Datos[0] = NumEmpleado; Datos[1] = Password; Datos[2] = check_admin; //Signals g_signal_connect(G_OBJECT (btn_Cancelar), "clicked", G_CALLBACK (Cerrar_Ventana),(gpointer) win_NuevoUsuario); g_signal_connect(G_OBJECT (btn_Guardar), "clicked", G_CALLBACK (Registrar_Usuario), Datos); }