[Kde-perl] How does shift->SUPER::NEW works?

Germain Garand germain at ebooksfrance.org
Thu May 27 03:49:25 CEST 2004

Le Jeudi 27 Mai 2004 01:14, Rafael Beccar a écrit :
> Hi,
> I'm having a hard time trying to properly use the constructor built by
> PerlQt Designer.
> I think my problem is that I don't understand how the following line
> works:
> shift->SUPER::NEW(@_[0..3]);

this line calls the constructor of the superclass.
@_[0..x] passes only the number of arguments the superclass's constructor 

given a package foo, that isa Qt::Widget

   foo( undef, "widget", 0, "some other arg" )

would eventually call

   foo->NEW( undef, "widget", 0, "some other arg" )

that is to say:

  foo::NEW( "foo", "undef, "widget", 0, "some other arg" )

and assuming foo::NEW contains:


would thus call
   foo->SUPER::NEW( undef, "widget", 0 )


   foo->Qt::Widget::NEW( undef, "widget", 0 )

that will build an instance of a Qt::Widget, setup the 'this' pointer and 
Qt::attributes accessors.

You don't need to return 'this' (i.e $self) at the end of the constructor: 
PerlQt takes care of that.

> What does this line do with the parameters passed to the constructor and
> how do I get them once the line was executed?

the @_ array isn't emptied in the process, so after the call, you still have
all the arguments at hand.

> If do this:
> my $arg = $_[1];
> shift->SUPER::NEW(@_[0..3]);
> I get the parameter I want in the $arg variable, but I think this is not
> the best way to do it as the first line is removed every time I run
> puic.

instead of hand-editing the puic generated code, you should consider 
subclassing it.
=> "Subclassing your GUI"


More information about the Kde-perl mailing list