[Kde-bindings] contextMenuEvent on a QGraphicsProxyWidget causes plasma to crash

Richard Dale rdale at foton.es
Tue Nov 18 13:58:06 UTC 2008


On Monday 17 November 2008 23:55:19 David Palacio wrote:
> A QGraphicsProxyWidget is a child of a PlasmaScripting::Applet. When the
> hosted widget is right-clicked (calling a context menu) plasma crashes. If
> the proxy or the proxied widget implements contextMenuEvent there is no
> crash. Affected kdebindings versions: 4.1.3 & trunk
>
> ===========Applet source code==============
> require 'plasma_applet'
>
> module PlasmaAppletHelloRuby
>
> class Main < PlasmaScripting::Applet
>
>   def initialize(parent, args = nil)
>     super
>   end
>
>   def init
>     resize(600, 400)
>     proxy = Qt::GraphicsProxyWidget.new self.applet_script.applet
>     proxy.widget = ( button = Qt::PushButton.new( 'Crash me' ) )
>     # Uncomment the following to prevent a crash
>     #class << proxy
>     ##class << button #or instead subclass the widget and
>     #                 #the crash still does not happen
>     #  def contextMenuEvent ( event )
>     #    STDERR.puts 'Do not crash plasma'
>     #  end
>     #end
>   end
>
>   def paintInterface(p, option, rect)
>     p.pen = Qt::Color.new 'steelblue'
>     p.scale 3, 3
>     p.draw_text Qt::RectF.new( rect ), 'Hello Ruby'
>   end
>
>   def constraintsEvent(constraints)
>   end
>
> end
>
> end
>
> ==P.S.==
> Actually, this is not the only crash. Resizing, rotating and moving may
> cause a crash if done a few times.
>
> ===========Plasma Konsole output ==============
> /.../KDE/plasma.rb:114: warning: Object#type is deprecated; use
> Object#class /.../KDE/plasma.rb:114: can't convert Class into Integer
> (TypeError) Plasma crashed, attempting to automatically recover
>
> =========Backtrace=========
The problem is to do with garbage collection. I turned off garbage collection  
with 'GC.disable' and the applet ran fine without crashing. So for now you 
need to put the proxy and button into instance variables like this, to prevent 
them being GC'd:

  def init
    resize(600, 400)
    @proxy = Qt::GraphicsProxyWidget.new self
    @button = Qt::PushButton.new( 'Crash me' )
    @proxy.widget = @button

The qtruby runtime will walk through trees of Qt::Objects and Qt::Widgets 
marking any with parents as not needing garbage collection. But I think with 
Qt::GraphicsItems as you have here, we haven't got the same tree to walk and 
that isn't working.

-- Richard





More information about the Kde-bindings mailing list