Re: How does shift->SUPER::NEW works?
Germain Garand <[email protected]>
| Newsgroups | gmane.comp.kde.devel.perl |
|---|---|
| Message-ID | <[email protected]> |
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 requires. e.g: 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: shift->SUPER::NEW(@_[0..2]) would thus call foo->SUPER::NEW( undef, "widget", 0 ) i.e: 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. see: http://perlqt.sourceforge.net/dist/current/doc/en/index.html#rad_prototyping_with_qt_designer_and_puic => "Subclassing your GUI" Greetings, Germain