re: Reference to a C++ object in GTK+ callbacks




 Paul,

 As it has been said, your function needs to have the correct format, i.e.

  gboolean play_cb (GtkWidget *widget, gpointer ptr) {}

 Andy

----------------------------------------
From: Paul Santa Maria <paulsm1021 yahoo com>
Sent: Tuesday, December 13, 2005 7:01 PM
To: gtk-app-devel-list gnome org
Subject: Reference to a C++ object in GTK+ callbacks 

Hi -

I'm using the GTK+ 2.6.4 that came with Suse 9.3. I'm coding in C++, but using the "raw" GTK+ C
libraries.

I'm trying to pass a pointer to one of my C++ classes into a callback, so that I can call a method
on that class. The code looks like this:

1. less hbaview.h =>
 --------------
class HbaviewApp
{
 ...
private:
 AnimationFile *m_animation;
 ...

class Hbafile : public AnimationFile
{
public:
 Hbafile (GtkWidget *da);
 virtual ~Hbafile ();
 virtual void open (const char *fname);
 virtual void close ();
 virtual void start ();
 ...

2. less HbaviewApp.cpp =>
 -------------------
void init ()
 ...
 GtkWidget *play = 
 gtk_image_menu_item_new_from_stock (
 "gtk-media-play", accel_group);
 gtk_widget_show (play);
 gtk_container_add (GTK_CONTAINER (menu3), play);
 gtk_signal_connect (GTK_OBJECT (play), "activate",
 G_CALLBACK (play_cb), m_animation);
 ...

3. less callbacks.cpp =>
 ------------------
gboolean
play_cb (gpointer data)
{
 // Deference the object pointer to do the actual work
 AnimationFile *ani = (AnimationFile *)data;
 ani->start ();
}

"ani->start()" works fine outside of the callback. I know my Animation object has been
successfully created and that "m_animation" points to it before I call gtk_signal_connect().

But it crashes with a signal SIGSEGV, Segmentation fault when the play_cb callback tries to call
ani->start().

Any idea what I might be doing wrong?

Or tips for debugging the problem?

Thanx in advance!

_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list





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