[Qtscript-bindings] Inheritance question (why call the parent constructor twice?)

Thiago Silva tsilva at sourcecraft.info
Sat Jul 11 01:36:51 CEST 2009


Hello,

I'm a little bit confused about performing inheritance of Qt objects.
In the examples and docs, the approach is, for a given "parent"
constructor, create a function with a parent.call(this) in it's body
and setup it's prototype property with a new parent object. This means
that "parent" is called twice: once with the new, to setup the child's
prototype, and the second in the child constructor function.

Knowing a little bit of the ecma-262 specs, I though this is odd, but
for immediate inheritance of Qt objects it was working fine. The
problem I'm having is when creating a bigger prototype chain with a Qt
object in the top of it: my constructors gets called twice. Is this a
technical difficulty to bind JS with qt/c++ classes, perhaps?

For example, the code below follows what the docs and examples do. It
works, but editor() obviously gets called twice:

//----begin
editor = function() {
  QTextEdit.call(this)
}
editor.prototype = new QTextEdit

subed = function() {
  editor.call(this)
}
subed.prototype = new editor

x = new QMainWindow
ed = new subed
x.setCentralWidget(ed)
x.show()
//----end

In the other hand, the following code is what I believe to be
preferred, but the editor doesn't appear inside the window:

//---begin
editor = function() {
  QTextEdit.call(this)
}
editor.prototype = new QTextEdit

subed = function() {
}
subed.prototype = new editor

x = new QMainWindow
ed = new subed
x.setCentralWidget(ed)
x.show()
//---end


Thanks in advance
-- 
Thiago Silva
Computer Science
M.Sc. Candidate at Federal University of Pernambuco
jabber/gtalk: tsilva at jabber-br.org
http://blog.sourcecraft.info


More information about the Qtscript-bindings mailing list