Re: change picture and text on button click



On Sat, Mar 04, 2006 at 09:09:26PM +0100, rupert wrote:
...
but I only get some error in the bash:

(spielkram:7144): GLib-GObject-WARNING **: IA__g_object_get_valist: object
class `GtkButton' has no property named `pixbuf'

...

void bild_aktualisieren(GtkImage *bild)

...

int main(int argc, char **argv)
{
...
    knopf = g_object_new(GTK_TYPE_BUTTON, "label", "fester", NULL);
...
    g_signal_connect(knopf, "clicked", G_CALLBACK(bild_aktualisieren),
    NULL);

So, bild_aktualisieren() gets `knopf' as its argument, which
is a GtkButton and the error message is right.

You do not even pass the image to change in the
g_signal_connect() userdata argument (it is NULL), so
I wonder how you expected bild_aktualisieren() to get the
image.  But even if you passed bild as the last argument of
g_signal_connect()

     g_signal_connect(knopf, "clicked", G_CALLBACK(bild_aktualisieren), bild);

the callback would get it as the *last* (second, in this
case) argument, or you would have to use
g_signal_connect_swapped() to swap the arguments instead

A few more notes.  Using g_object_set() and g_object_get()
for everything can seem generic and cool, but it gives you
absolutely no compile time type checking -- unlike direct
getters and setters like gtk_image_set_from_pixbuf() (that
are also somewhat faster, but this is not the main point).
The line

    g_object_get(bild, "pixbuf", &pixbuf, NULL);

is redundant as you immediately assign something else to the
pixbuf variable on the next line -- what you are trying to
acomplish by that?  Should your programs ever be open-source
and/or internationalized, stop using national symbol names
and/or messages right now, it will save you much grief later.

Yeti


--
That's enough.



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