Re: how copy gchar* pointer to other gchar*, send two widgets refs to callback function ?



Am Dienstag, den 01.03.2005, 15:01 -0600 schrieb Mario Lopez:
> Greetings ....

Hi Mario. You should write similar requests for help on application
programming to gtk-app-devel-list instead of gtk-devel-list in future.

> I want to ask something to them about this function
> [...]
> but when copying the content the program crash...

You didn't provide enough information. I suppose your use_data isn't
passed correctly; I'm willing to help you in private - simply send me a
mail with more code and we figure out what's wrong -, but dealing with
these kinds of faulty programming issues is really boring for GTK+
developers.

> another question....
> 
> void on_btnEnviar_clicked (GtkButton *button, gpointer  user_data)
> 
> recives at user_data  a reference to textview widget, but how can
> recive the textview and other widget ? by example a reference to
> combobox, something like.
> 
> void on_btnEnviar_clicked (GtkButton *button, gpointer  textview,
> gpointer cbowho)

Short answer: Doesn't work. You can only pass one extra gpointer per
callback. I see two ways of resolving this:

1. Clean
========
Model your widgets into a new object, which is derived from an existing
GTK+ widget class. For example, use a dialog and put the single widgets
into a private data structure. There are many examples available on the
net, for instance [1]. You'd simply pass the struct containing all
relevant widgets as user data.

2. Quick and Dirty
==================
Write a struct containing relevant data for your callback:
typedef struct {
  GtkWidget *textview;
  GtkWidget *combobox;
} CallbackData;

For signal connection, you'd use:

...
{
  GtkWidget    *button;
  GtkWidget    *textview;
  GtkWidget    *combobox;
  CallbackData  cb_data;

...
  button = ...;
...
  textview = ...;
...
  combobox = ...;
...

  cb_data.textview = textview;
  cb_data.combobox = combobox;

  g_signal_connect (button "clicked",
		    G_CALLBACK (my_button_clicked), &cb_data);
}

you'd use
static void
my_button_clicked (GtkButton    *button,
		   CallbackData *cb_data)
{
   operate_on_textview (cb_data->textview);
}


[1]
http://cvs.gnome.org/viewcvs/*checkout*/gnome-menu-editor/src/gme-main-dialog.c?rev=1.2

-- 
Christian Neumair <chris gnome-de org>




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