Re: [gtk-list] Re: How to use a gpointer?



On Wed, 3 Mar 1999, Christian B. Westermann wrote:

> > and the_value=*((int*)date);
> > This should work.
> 
> No, it didn't. What do you mean with "as far as gpointer is void*"?
> Can you maybe give me another example, how you can pass an int into a
> GTK_SIGNAL_FUNC using the gpointer?

for me it works, Chris,  you can have a look into attachment and it cant
be other. According to glib.h gpointer is pointer of void type:

typedef void* gpointer;

So ANY pointer (*int too) can be cast to it. The problem can occure only
casting not pointer type to pointer, but this never happense, as I know.

Good Luck,

_____
Alexander Kotelnikov
Saint-Petersburg, Russia
mailto:sacha@ak2614.spb.edu
#include <gtk/gtk.h>
void destroy( GtkWidget *widget,
              gpointer   data )
{
    gtk_main_quit();
}


void gpointer_data( GtkWidget *widget,
            gpointer   data )
{
    g_print ("%d\n",*((int*)data));
}

int main( int   argc,
          char *argv[] )
{
    int val=10;
    GtkWidget *window;
    GtkWidget *button;
    
    gtk_init(&argc, &argv);
    
    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    
    gtk_signal_connect (GTK_OBJECT (window), "destroy",
			GTK_SIGNAL_FUNC (destroy), NULL);
    
    gtk_container_set_border_width (GTK_CONTAINER (window), 10);
    
    button = gtk_button_new_with_label ("Hello World");
    
    gtk_signal_connect (GTK_OBJECT (button), "clicked",
			       GTK_SIGNAL_FUNC (gpointer_data),
			       (gpointer)(&val));
    
    gtk_container_add (GTK_CONTAINER (window), button);
    
    gtk_widget_show (button);
    
    gtk_widget_show (window);
    
    gtk_main ();
    
    return(0);
}


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