Bug 126985 - Qtruby inherited constructor called 2 times before 'super'
Summary: Qtruby inherited constructor called 2 times before 'super'
Status: RESOLVED UNMAINTAINED
Alias: None
Product: bindings
Classification: Developer tools
Component: general (show other bugs)
Version: unspecified
Platform: Gentoo Packages Linux
: NOR wishlist
Target Milestone: ---
Assignee: kde-bindings
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-05-08 21:46 UTC by Maël Clérambault
Modified: 2022-12-22 06:52 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Maël Clérambault 2006-05-08 21:46:56 UTC
Version:            (using KDE KDE 3.5.2)
Installed from:    Gentoo Packages

sample script:
--------------

require 'Qt'

class A < Qt::Object
  def initialize
    p 'A'
    super
    p 'A end'
  end

end

A.new

outputs:
---------

"A"
"A"
"A end"


Everything before the 'super' call is executed 2 times.
Comment 1 Caleb Tennis 2006-05-16 16:44:29 UTC
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.
Comment 2 Richard Dale 2006-05-16 20:55:25 UTC
On Tuesday 16 May 2006 15:44, Caleb Tennis wrote:
[bugs.kde.org quoted mail]
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)
		init()
		...

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++
instance.

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
Comment 3 Justin Zobel 2021-03-09 05:24:42 UTC
Thank you for the bug report.

As this report hasn't seen any changes in 5 years or more, we ask if you can please confirm that the issue still persists.

If this bug is no longer persisting or relevant please change the status to resolved.
Comment 4 Mathieu Jobin 2022-12-22 06:52:24 UTC
QtRuby only existed for Qt4 and Korundum, which never got updated for 5.x

This is unmaintained and any effort towards QtRuby for Qt6 will be from scratch.

Therefore, closing this ticket