Trolltech Home | QSA-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 1

QSA-interest Archive, November 2006
Re: Class definition weirdness


Message 1 in thread

Simon, Cheryl wrote:
> I am having some odd behavior surrounding when QSA thinks that my class
> is defined.  Here is some sample code:

...

> If I click on the box, I get an error message saying "Error.  Use of
> undefined variable Bar".  If I replace the top two lines with:
> 
> Var foo = new Foo();
> foo.test();
> 
> Then it works just fine.  I'm thinking must have something to do with
> the differing scope when "test" is called through a signal rather than
> directly, but it seems that it should understand that Bar is a class in
> either situation.  Anyone have a fix for this, or know a way around it?
> Thanks!
> 
> Cheryl Simon
> Cheryl.Simon@xxxxxxx

Hi Cheryl,

I'm looking into this but I am unable to reproduce it with the attached 
example.

best regards,
Gunnar

#include <qsinterpreter.h>
#include <qsinterpreter.h>

#include <qapplication.h>

class Object : public QObject
{
    Q_OBJECT
public:
    Object(QObject *parent = 0, const char *name = "context")
        : QObject(parent)
    {
        setObjectName(name);
    };

    void emitDummySignal() { emit dummySignal(); }

signals:
    void dummySignal();
};



int main(int argc, char **argv)
{
    QApplication app(argc, argv);
    QSInterpreter ip;
    Object *obj = new Object;
    ip.addTransientObject(obj);

    ip.evaluate(
                "var foo = new Foo();                           " \
                "connect(context, \"dummySignal()\", foo.test); " \
                "                                               " \
                "class Foo                                      " \
                "{                                              " \
                "	function Foo(){}                        " \
                "	function test()                         " \
                "	{                                       " \
                "	    var bar = new Bar();                " \
                "           print('created '  + bar);           " \
                "	}                                       " \
                "}                                              " \
                "                                               " \
                "class Bar                                      " \
                "{                                              " \
                "	function Bar(){}                        " \
                "}                                              "
                );

    obj->emitDummySignal();



    delete obj;
};
#include "classstuff.moc"