On Thursday 15 October 2009 19:40:23 Olivier Goffart wrote:
> > Hmm - I'm absolutely sure its defined nowhere else in my (rather huge)
> > application.
>
> Maybe it has to do something with the file that are included?
>
> > But my usecase is a little different:
> >
> > qs:
> > var child = Form.findChild ("child1");
> > var children = child.findObjects ("MyClass");
>
> I know no findObjects function in Qt.  maybe you meant findChildren?
> Still the attached code does work work for me, both with 4.5 and 4.6.

Ooops - forgot to mention where findObjects comes from.

> Some compilable code sample would be really usefull.

This reproduces the bug:

#include <QtGui>
#include <QtScript>


class MyTest : public QObject {
   Q_OBJECT;
 public:
   MyTest (QObject * parent) : QObject (parent) {}
   virtual ~MyTest () {}

   Q_INVOKABLE QObjectList findObjects (const QString & className) const {
      QObjectList result;
      QObjectList list = qFindChildren <QObject *> (this, QString ());
      foreach (QObject * obj, list) {
         if (qstrcmp (obj->metaObject ()->className (), className.toAscii ()) 
== 0) {
            result.append (obj);
         }
      }
      return result;
   }

};

#include "main.moc"

int main(int argc, char **argv)
{
   QApplication app (argc, argv);
   QScriptEngine e;

   QObject * o = new QObject;
   MyTest * t = new MyTest (o);
   t->setObjectName ("mytest");
   QObject * c = new QObject (t);
   c->setObjectName ("child1");

   e.globalObject ().setProperty ("Form", e.newQObject (o));

   e.evaluate(
              "function init () {"
              "   print (\"init called\");\n"
              "   try {\n"
              "      var child = Form.findChild(\"mytest\");\n"
              "      print (\"child: \" + child);\n"
              "      var children = child.findObjects (\"QObject\");\n"
              "      print (\"children: \" + children);\n"
              "   } catch (error) {\n"
              "      print (\"Error: \" + error);\n"
              "   }\n"
              "   print (\"init done\");\n"
              "}\n");

   QScriptValue scriptValue = QScriptValue (e.globalObject ().property 
("init")).call ();

}


Frank
_______________________________________________
Qt4-preview-feedback mailing list
[email protected]
http://lists.trolltech.com/mailman/listinfo/qt4-preview-feedback

Reply via email to