From b7dfb78902c7d43e0f91226aa39796a731232df3 Mon Sep 17 00:00:00 2001 From: Kent Hansen Date: Wed, 5 Nov 2008 16:26:06 +0100 Subject: 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. --- generator/shellimplgenerator.cpp | 12 ++++++++++-- 1 file 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 << " "; -- cgit v1.2.3