[Kde-bindings] QtRuby File menu vanishing

Richard Dale Richard_Dale at tipitina.demon.co.uk
Tue Jun 21 15:17:12 UTC 2005


On Tuesday 21 June 2005 17:56, Mark Somerville wrote:
> On Tuesday 21 June 2005 15:41, Richard Dale wrote:
> > On Tuesday 21 June 2005 13:28, Mark Somerville wrote:
> > > I have had this problem in a couple of QtRuby applications that I've
> > > written and haven't got a clue what is causing it. The menu appears and
> > > operates fine when the program is first started. However, after a
> > > seemingly random (1-15) GUI events (button presses, widget
> > > resizing...), the file menu vanishes, never to be seen again. If there
> > > are other menus too, then they sometimes vanish too.
> > >
> > > Has anyone else had any problems like this? Does anyone know what is
> > > causing it?
> > >
> > > My code is quite straightforward, so I suspect it's a problem somewhere
> > > else.
> > >
> > > filemenu = Qt::PopupMenu.new
> > > filemenu.insertItem("&Quit", self, SLOT('quit()'))
> > > menu = menuBar()
> > > menu.insertItem("&File", filemenu)
> > >
> > > Any clues?
> >
> > It looks to me as though menu.insertItem() doesn't make the menuBar the
> > parent of the filemenu (I'll check that to make sure). Therefore, it
> > would get garbage collected because the mark phase of ruby garbage
> > collection would think it's ok to delete the popup menu once the local
> > variable 'filemenu' has gone out of the ruby scope. What if filemenu is a
> > global variable '$filemenu' or instance variable '@filemenu' does it
> > still happen? Could you post a complete small example program that
> > reproduces the problem?
>
> That makes perfect sense, but hadn't even crossed my mind (although I'm not
> sure why not)! Making the menu a class variable solves the problem - thanks
> a lot.
OK, good. I'll try and fix that soon. I was about to do another QtRuby release 
on RubyForge, but got stuck with an autoconf problem. So just as well you 
found this bug before the release..

-- Richard



More information about the Kde-bindings mailing list