[Kde-bindings] [Bug 126985] Qtruby inherited constructor called 2 times before 'super'

Richard Dale Richard_Dale at tipitina.demon.co.uk
Tue May 16 18:54:31 UTC 2006

On Tuesday 16 May 2006 15:44, Caleb Tennis wrote:
> ------- You are receiving this mail because: -------
> You are the assignee for the bug, or are watching the assignee.
> http://bugs.kde.org/show_bug.cgi?id=126985
> ------- Additional Comments From caleb aei-tech com  2006-05-16 16:44
> ------- This is a known 'issue', due to the way QtRuby works.  I believe
> the workaround is to make sure you call super first, but I'll let Richard
> chime in. _______________________________________________
I thought I already added a comment to this report. Here is the comment from 
the Qt.cpp code, that tries to explain the problem, and the reason why code 
before the super call is run twice:


class LCDRange < Qt::Widget

	def initialize(s, parent, name)
		super(parent, name)

For a case such as the above, the QWidget can't be instantiated until
the initializer has been run up to the point where 'super(parent, name)'
is called. Only then, can the number and type of arguments passed to the
constructor be known. However, the rest of the intializer
can't be run until 'self' is a proper T_DATA object with a wrapped C++

The solution is to run the initialize code twice. First, only up to the
'super(parent, name)' call, where the QWidget would get instantiated in
initialize_qt(). And then rb_throw() jumps out of the
initializer returning the wrapped object as a result.

The second time round 'self' will be the wrapped instance of type T_DATA,
so initialize() can be allowed to proceed to the end.

An ordinary Ruby instance is a T_OBJECT type in the C code, but once it wraps 
a C++ instance it is a T_DATA. So it is very difficult to work round it 
without the 'run twice' fix.

-- Richard

More information about the Kde-bindings mailing list