Re: GTK2 with c++, without gtkmm



Progss wrote:
Hi all!

I've been just a reader of this mailing-group, but it seems to me, that
now I've got a problem which cannot be solved just after reading :)

I'm writing an application using GTK2, however I decided to use
C++ because of it's objects :) I tried not to pay attention to some
difficulties, but they return. Type matching is too strict, so after e.g:

[cut]
    hsep = gtk_hseparator_new();
    gtk_table_attach(GTK_TABLE(packTable), hsep , 0,2,2,3,
                                GTK_FILL|GTK_SHRINK, GTK_FILL, // *** HERE!
                                0,0 );
[cut]

error message is like that:
---
cannot convert `int' to `GtkAttachOptions' for argument
`7' to `gtk_table_attach (GtkTable *, GtkWidget *, unsigned int, unsigned
int, unsigned int, unsigned
int, GtkAttachOptions, GtkAttachOptions, unsigned int, unsigned int)'
---


Unlike C, C++ wont let you assign OR'd bit values to an enum, you have to do a cast, like so:

...
(GtkAttachOptions)GTK_FILL|GTK_SHRINK,
...

There are also problems when try to call  g_signal_connect()
passing a static class method as a callback function.

I'm using "gpointer data" to pass extra data, because
in a static function I cannot access non-static class members.

SOMETHING LIKE AN EXAMPLE:

class Foo {
public:
    GtkWidget* button;
    static void callback(GtkWidget* widget, gpointer data);
    gint foo2;
};

[,,,]   g_signal_connect (G_OBJECT (button), "clicked",
                    G_CALLBACK (callback), (gpointer) this->foo2);


this->foo2 is a copy of foo2, (a temporary value), not the address of foo2. So you can only read the value passed. You can't assign a value to it.

void Foo::callback(GtkWidget* widget, gpointer data
    (gint) data=5;
[...] }


You can't do this:

(gint) data=5;

You are trying to assign a value to a temporary value for use outside the function.

... does not work - I got an errortrying to access foo2
- "invalid use of member in static member function"

works only:
[,,,]   g_signal_connect (G_OBJECT (button), "clicked",
                    G_CALLBACK (callback), (gpointer) this);
and then:
[...] ((Foo*)this)->foo2 = 5;

Is there a way to solve those problem?
Or does anyone see where I made my mistakes?


This is correct:

((Foo*)this)->foo2 = 5;

You have to assign a value to this->foo2 through the pointer passed in data.


Thanks,
Waldek Maleska


----------------------------------------------------------------------
Zostan trenerem kadry skoczkow i wygraj bilet pod skocznie!

http://link.interia.pl/f16a5



_______________________________________________
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]