diff options
author | Kent Hansen <khansen@trolltech.com> | 2008-11-05 16:26:06 +0100 |
---|---|---|
committer | Kent Hansen <khansen@trolltech.com> | 2008-11-05 16:26:06 +0100 |
commit | b7dfb78902c7d43e0f91226aa39796a731232df3 (patch) | |
tree | b70207dc9ca05ee9f65704695177c6f7be1e52b8 | |
parent | 7a56f4e92a0ad77509abac176d5701d384cb09e5 (diff) |
Fixes: avoid infinite recursion when calling QProgressBar.show
Task: http://code.google.com/p/qtscriptgenerator/issues/detail?id=8
Details: The situation occurs when the virtual function QProgressBar::text() is called from C++.
As usual, the binding will try to look up a property with the corresponding name ("text")
in the script object. "text" is also the name of a Qt (C++) property, so it will be
resolved through the dynamic QObject binding, which will call the C++ getter again, and so
on and so on...
This submit fixes the problem by having the binding add a "_qs_" prefix when doing the
script property lookup; so if a script wanted to reimplement the text() function, it
would have to store it in a property named _qs_text. Probably not optimal, but at least
it fixes the recursion while still allowing you to reimplement the function. It might
or might not become the official (i.e. documented) way of doing it, at some point.
-rw-r--r-- | generator/shellimplgenerator.cpp | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/generator/shellimplgenerator.cpp b/generator/shellimplgenerator.cpp index e4cf63f..b468caa 100644 --- a/generator/shellimplgenerator.cpp +++ b/generator/shellimplgenerator.cpp @@ -133,10 +133,18 @@ void ShellImplGenerator::write(QTextStream &s, const AbstractMetaClass *meta_cla Option(OriginalName | ShowStatic | UnderscoreSpaces), "QtScriptShell_"); s << endl << "{" << endl; + QString scriptFunctionName = fun->name(); + if (QPropertySpec *read = meta_class->propertySpecForRead(fun->name())) { + if (read->name() == fun->name()) { + // use different name to avoid infinite recursion + // ### not sure if this is the best solution though... + scriptFunctionName.prepend("_qs_"); + } + } s << " QScriptValue _q_function = __qtscript_self.property(\"" - << fun->name() << "\");" << endl; + << scriptFunctionName << "\");" << endl; s << " if (!_q_function.isFunction() || QTSCRIPT_IS_GENERATED_FUNCTION(_q_function)" << endl - << " || (__qtscript_self.propertyFlags(\"" << fun->name() << "\") & QScriptValue::QObjectMember)) {" << endl; + << " || (__qtscript_self.propertyFlags(\"" << scriptFunctionName << "\") & QScriptValue::QObjectMember)) {" << endl; AbstractMetaArgumentList args = fun->arguments(); s << " "; |