g_signal_connect problem



I dont' understand why this simple code doens't work:

#include <iostream>
using namespace std;

#include <gtk/gtk.h>

gint cb_button( GtkWidget* widget,
                GdkEvent* event,
                gpointer callback_data );

int
main( int argc, char** argv )
{
  GtkWidget* win;
  GtkWidget* button;

  gtk_init( &argc, &argv );

  win = gtk_window_new( GTK_WINDOW_TOPLEVEL );

  button = gtk_button_new_with_label( "press-me" );
  gtk_container_add( GTK_CONTAINER( win ), button );

  int x = 10;

  cout << "x address = " << &x << endl;

  g_signal_connect( GTK_OBJECT( button ), "clicked",
                    G_CALLBACK( cb_button ), (void*)&x );

  gtk_widget_show_all( win );

  gtk_main();

  return 0;
}

gint cb_button( GtkWidget* widget,
                GdkEvent* event,
                gpointer callback_data )
{
  cout << "x address from callback = " << callback_data << endl;

  return TRUE;
}


Compiled with:
--------------------
g++ `pkg-config --cflags gtk+-2.0` -o test2b test2b.cxx `pkg-config --libs 
gtk+-2.0`
./test2balpha ~/qt-explained/code/gtk/src $ ./test2b
x address = 0xbffff110
x address from callback = 0xbfffe08c

The address in callback differs from original passed data ! ???


someone can gently take me some chanches to live anymore without hacks entire 
glib/gobject/gtk ?:)


bye
Lore




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