[Kde-perl] Why isn't this easy? implementing File->New

Joe Carlson joe at fruitfly.org
Wed Aug 2 02:04:44 CEST 2006


On Tue, 2006-08-01 at 19:35 -0400, darrik wrote:
> I've found this works, and I'm thinking it has to do with variables 
> going out of scope, automagic destructors, and perl garbage collecting.
> 
> sub processFileMenu {
> 	if ($option==FILENEW) {
> 		our $newwin->{this()}=MyView();
> 		$newwin->{this()}->show();
> 	}
> }

> I haven't gotten any subclasses to work with "my" variables allocated in 
> subs, so I've been using this workaround throughout.
> 

yes. thanks. this is a good point. And a clue of what's going on. I've
been use'ing strict so the  main:: qualifier was needed - and I tend to
'my' variables indiscriminately. If I just convert my 'my' to an 'our',
then I can get one new copy of the main window to appear.

Strangeness re-appears when I then select File->New again. The newly
created window disappears and a newer one appears in its place.

I just tried a workaround of creating a list at global scope and pushing
references to the new main windows onto the list as they are created.
This prevents the garbage collection and I can now open multiple
windows.

This is starting to make some sense now...

joe
 
> If someone has a better idea, I'd love to hear it.
> 
> (Also, from the example you can see the main:: namespace is unecessary 
> on your call to MyView().)
> 
> Darrik Mazey
> 
> Joe Carlson wrote:
> > I am liking PerlQt. At last, some real widgets that enable access to our
> > Perl infrastructure. I'm a convert.
> > 
> > Nonetheless, a problem. I'd like to implement a "File->New" menu action
> > to open a new instance of the main window. In the c++ version, this is
> > trivial:
> > 
> > void MyView::processFileMenu(int option)
> > {                                                                                                               
> >   if (option == FILENEW) {
> >     MyView *newWindow = new MyView();
> >     newWindow->show();
> >   }
> > ...
> > 
> > and that's it. the new window opens and I have an event loop responding
> > to it.
> > 
> > The corresponding perl version (inside MyView.pm which subclasses
> > Qt::MainWindow):
> > 
> > package MyView;
> > ...
> > use constant FILENEW=>1;
> > ...
> > sub processFileMenu
> > {
> >   my $option = shift;
> >   if ($option == FILENEW) {
> >     my $newWindow = main::MyView();
> >     $newWindow->show;
> >   }
> > ...
> > 
> > is not as successful. I can see from the perl debugger that I am calling
> > MyView::NEW and I am creating a new instance of the main window. But
> > nothing shows up on the screen. The X event loop continues to process
> > events from the original main window.
> > 
> > Am I correct in assuming that I need to invoke the constructor from the
> > namespace main::? I have been unable to find any other legitimate way to
> > call it. Are there any alternatives for creating new instances of these
> > classes directly?
> > 
> > I looked at some of the trace output from the debugger, and I am left
> > with the impression that there may be some processing that happens only
> > the first time a module is autoloaded that prevents new instances from
> > getting processed by the metaObject-izer.
> > 
> > Anyone have a suggestion? I haven't stumbled over the solution yet.
> > 
> > Thanks,
> > 
> > Joe
> > 
> > 
> > 
> > _______________________________________________
> > Kde-perl mailing list
> > Kde-perl at kde.org
> > https://mail.kde.org/mailman/listinfo/kde-perl
> > 
> 
> _______________________________________________
> Kde-perl mailing list
> Kde-perl at kde.org
> https://mail.kde.org/mailman/listinfo/kde-perl
> 



More information about the Kde-perl mailing list