[Kde-perl] Why isn't this easy? implementing File->New
darrik
darrik at mythofbutterfly.com
Wed Aug 2 07:52:01 CEST 2006
Ashley Winters wrote:
> use strict;
> use Qt; # use Qt in EVERY package! It declares 'this', and does
> other use-strict-happy things
> use MyView;
> sub processFileMenu {
> if ($option==FILENEW) {
> MyView(this)->show;
> }
> }
You're not storing a perl reference to the new window anywhere. What
happens when you want to access that window from the parent later?
This is more evident when you subclass a container widget that has child
controls. For instance:
use strict;
package MyWidget;
use Qt;
use Qt::isa qw( Qt::Widget );
sub NEW {
# irrelevant method arguments left out for brevity :P
my $class=shift;
my $parent=shift;
shift->SUPER::NEW($parent);
my $layout=Qt::HBoxLayout(this);
my $lbl=Qt::Label("label",this);
$layout->addWidget($lbl);
}
sub changeChildLabel {
# how do you access $lbl here?
}
This part has me confused. Storing $lbl in a package variable doesn't
work if you instantiate several MyWidget's. I've been using workarounds
that are inelegant, so a pointer to the *proper* way to do this would be
immensely appreciated.
Thanks,
Darrik Mazey
More information about the Kde-perl
mailing list