Re: [Vala] signal activate



Am 04.03.2010 16:39, Arley Consuegra Rosello wrote:
Hello, the signal 'activate'  from MenuItem don't expect any argument,
this say 
http://valadoc.org/gtk+-2.0/Gtk.MenuItem.activate.html

but in the doc of Gtk apear "GtkMenuItem *menuitem, gpointer user_data"
like argument.

'void* user_data' should never be exposed to Vala. If you're using Gtk.Builder
then 'user_data' is implicitly used to pass the argument that was
previously given to the '.connect_signals()' method to the handler.
Within the handler it will become the instance reference ('this').

That's why you must annotate auto-connected handlers with
'[CCode (instance_pos = -1)]' which means "the instance is implicitly
passed as the last argument" -- contrary to normal methods where the
instance reference is implicitly passed as the first argument.

The first argument of the handler should always be the signal source, in your
case 'Gtk.MenuItem menuitem'.

Some times when I use these signal without parameter work fine, example

public void some_thing(){
stdout.printf("I'm activate ");
}

In this case you do not access 'this'. That's why it works.

but in other cases and error apear (11 segmentation default)

In these cases you probably access 'this' (either explicitly or implicitly
by accessing a field or by calling an instance method). But 'this' is 'null',
so you'll get a segmentation fault.

 if y add
an argument (void* data) all work fine.

public void some_thing(void* user_data){
.
.
some_thing_here
.
.
}

You think it's 'user_data', but actually it's the signal source! The right
method signature is:

[CCode (instance_pos = -1)]
public void some_thing(Gtk.MenuItem menuitem) {
        // ...
}

The source is passed as the first argument and the instance ('this')
is implicitly passed as the last argument (via 'user_data' in C code).

It, is a bug, a documentation error or my error.

If you're using Gtk.Builder your handler should always have all arguments
except 'user_data'. If you're leaving out one argument the instance
reference will be mapped to the wrong argument.


Best regards,

Frederik



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