PDA

View Full Version : Using QSA: A very basic question



yogeshm02
25th January 2006, 16:15
Hi!

I want to make my Qt4.1 application scriptable, but am having trouble. My app has something like below: -


-
Object A
/ \
Object AA Object AB
/ \
Object AAA Object AAB

i.e 'Object A' has two members 'Object AA' & 'Object AB' and 'Object AA' has two more members 'Object AAA' & 'Object AAB'.

I want all of the above objects accessible from script. For this QSA doc says:



By passing an object to the scripting engine (using QSInterpreter::addTransientObject() or QSProject::addObject()), this object and all its signals, slots, properties, and child objects are made available to scripts


Does it means the following code alone would expose all objects to script:-


//Constructor of object A
setObjectName("ObjectA");
//Initialise all objects
.
.
.
.
qsProject = new QSProject(this);
qsProject->addObject(this);


Upon execution (While setting any property of 'ObjectAA') my app says 'ObjectAA' is undefined. This applies to all objects except 'ObjectA'.
I have also tried adding all objects to the projects but result is same.

Am i missing something? Please guide me.

Thanks in advance

axeljaeger
25th January 2006, 22:46
I think "child" doesn't mean a member variable but a child in a QObject-way: You have to pass ObjectA as parent to the constructor of ObjectAA to make AA become a child of A.

yogeshm02
26th January 2006, 07:25
I think "child" doesn't mean a member variable but a child in a QObject-way: You have to pass ObjectA as parent to the constructor of ObjectAA to make AA become a child of A.
I am already doing that.

I've attached copy of a trial app which i use for testing behaviour of QSA. You can try to look for loop-holes in the code. Doing only make will compile it. Upon executing it, you will find an editor widget which is used for executing script code. It is fairly easy. :cool:

yogeshm02
26th January 2006, 08:34
For those who are too lazy to look into attachment, here is code present in the constructor of base object:


setObjectName("trial");
editor = 0;

qsProject = new QSProject(this);

m_pButton1 = new QPushButton("First", this);
m_pButton2 = new QPushButton("Second", this);
m_pButton2->move(20, 0);
m_pButton1->setObjectName("button");
m_pButton2->setObjectName("buttons");


widget = new MyWidget(this, qsProject);
widget->setObjectName("container_");
widget->resize(50, 50);
widget->move(50, 50);

m_pLabel1 = new MyLabel(this);
m_pLabel1->setText("Hello World!");
m_pLabel1->move(100, 100);

m_pLabel2 = new MyLabel(this);
m_pLabel2->setText("Are You Listning?");
m_pLabel2->move(100, 105);

resize( 200, 200);

// qsProject->addObject(m_pButton1);
// qsProject->addObject(m_pButton2);
// qsProject->addObject(widget);
qsProject->addObject(this);

editor = new ScriptEditor( qsProject );
editor->show();