[Kde-bindings] name conflict between Qt::Widget#raise and Kernel#raise

David Palacio dpalacio at uninorte.edu.co
Sun May 24 16:45:27 UTC 2009


On Domingo 24 Mayo 2009 07:35:52 Stefano Crocco escribió:
> From inside a Qt::Widget, you can't raise an exception using raise, because
> it's shadowed by Qt::Widget#raise method. For example, take the following
> code:
>
> class W < Qt::Widget
>
>   def raise_error
>     raise RuntimeError, "This is an exception"
>   end
>
> end
>
> a = Qt::Application.new []
> w = W.new
> w.raise_error
>
> What I'd expect, of course, is a RuntimeError raised by the last line of
> code. Instead, ruby attempts to call Qt::Widget#raise and gives a
> NoMethodError because Qt::Widget#raise takes no argument.
>
> I can solve this problem by calling Kernel.raise instead of simply raise,
> but I think this is:
> a) confusing for the user, who might even not be aware that raise is a
> method and think it a keyword
> b) undesirable, because I think it's much more common to want to raise an
> exception than to use Widget#raise.
>
> In my opinion, the best course of action would be to rename
> Qt::Widget#raise to Qt::Widget#raise_widget or Qt::Widget#raise_to_top or
> something similar, so that Kernel#raise can be freely accessed.
>
> Stefano
> _______________________________________________
> Kde-bindings mailing list
> Kde-bindings at kde.org
> https://mail.kde.org/mailman/listinfo/kde-bindings
That is expected in Ruby's inheritance. And «raise» is not the only method 
overriden in a Qt class (as «exec», «load» and others). Changing this will 
only make QtRuby have many special cases (and break existing code). IMO, 
Kernel.method is the best solution for these rare cases.

And actually, I wouldn't raise an Exception inside a Widget. Instead, I'd emit 
a signal.



More information about the Kde-bindings mailing list