Re: GTK+1.3 classes. and www com
- From: Rob Nikander <nikander nc rr com>
- To: gtk-app-devel-list gnome org
- Subject: Re: GTK+1.3 classes. and www com
- Date: Tue, 26 Mar 2002 13:45:22 -0500
I recommend checking out the source of the Inti project to see how you
could do this. That's what I did a while back and it helped. (Or you
could just use gtkmm) Basically you have to set up a function for GTK to
call that is not a normal member function -- it has to be a static
function or a free function. Then you need to pass the "this" pointer as
"data" argument for the callback. That function in turn calls your
object's method. So something like....
gtk_signal_connect( GTK_OBJECT(button), "clicked",
GTK_SIGNAL_FUNC( the_static_or_free_function ), this); // this being
the Window object
...
...
void the_static_or_free_function(GtkButton * b, gpointer data)
{
Window * w = static_cast<Window*>(data); // not sure if static_cast is
right here...
w->on_button_click();
}
If I remember right, the C++ GTK wrappers have a few generic functions or
"function object" classes that they use over and over again -- you don't
have to write a static function every time you want to do this.
Rob
On Tue, 26 Mar 2002 09:58:28 -0800
"David Larsson" <dls www com> wrote:
Hi, I have a problem conserning gtk and classes in c++..
It's when I call class-method from a class-method with the help of
gtk_signal_connect().
Short example.
---Cut here----
class Window {
public:
GtkWidget *button;
Window() {
gtk_signal_connect(GTK_OBJECT(button), "clicked",
GTK_SIGNAL_FUNC(button_functio), NULL);
}
void button_function() {
/* Some junk here. */
}
}
void Window::button_function()
{
/* Some junk here. */
}
int main(int argv, char **argc)
{
gtk_init(&argv, &argc);
Windows w;
gtk_main();
}
---and here---
(Lacks a lot of things to make it work, but just a short example)
This doesn't work, and you get a error-message of the type 'void <*>' is
not 'void', but if I change void button_function() to static void
button_function() this works, but ofcourse I can't have the function
static. Any ideas?
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]