c++ - GTK 3 How to connect one signal to multiple widgets? (part 2) -


this continuation of question: gtk 3 how connect 1 signal multiple widgets?

i have code in c++ using gtk3.

it creates 2 text entries , 1 button. want action done text entered when button pressed. (in case want text printed.) code following:

#include <iostream> #include <gtk/gtk.h> using namespace std;  gtkwidget *wventana; gtkwidget *wgrid;  typedef struct {     gtkwidget *entrada1, *entrada2; } widgets;  void on_procesar (gtkbutton *procesar, widgets *w) {     const char * texto = gtk_entry_get_text(entrada1);     cout << texto << endl; }  void ventana(string titulo, int margen) {     const char * tituloc = titulo.c_str();      wventana = gtk_window_new (gtk_window_toplevel); }  void grid() {     wgrid = gtk_grid_new();     gtk_container_add(gtk_container(wventana), wgrid); }  gtkwidget *boton(string texto, int x, int y, int lx, int ly) {     const char * wtexto = texto.c_str();      gtkwidget *wboton;     wboton = gtk_button_new_with_label (wtexto);     gtk_grid_attach (gtk_grid (wgrid), wboton, x, y, lx, ly);     return wboton; }  gtkwidget *entrada(int x, int y, int lx, int ly) {     gtkwidget *wentrada;     wentrada = gtk_entry_new();     gtk_grid_attach (gtk_grid (wgrid), wentrada, x, y, lx, ly);     return wentrada; }  //inicio int main(int argc, char *argv[]) {     gtk_init (&argc, &argv);      ventana("ventana",10);     grid();      widgets *w = g_slice_new (widgets);     w->entrada1 = entrada (2, 1, 1, 1);     w->entrada2 = entrada (2, 2, 1, 1);     gtkwidget * procesar = boton ("procesar", 2, 3, 1, 1);     g_signal_connect(procesar, "clicked", g_callback (on_procesar), w);      gtk_widget_show_all (wventana);     gtk_main ();     g_slice_free (widgets, w);      return 0; } 

right problem in on_procesar() dont know how text entries, because don't know how indicate entry widget want use. (its not defined in scope).

please can explain me how can done?

use w->entrada1 in on_procesar() handler instead of entrada1. point of structure w keep track of widgets want use in various signal handlers, can keep them in scope passing w user data each handler.


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -