PDA

View Full Version : Please help with QtScript



Haccel
16th December 2008, 05:59
How to raise function of some object in script.

I create some object in script:



QScriptValue socket_ctor(QScriptContext *context, QScriptEngine *engine)
{
QString ip;
quint16 port;

ip = context->argument(0).toString();
port = context->argument(1).toUInt16();

Server* ss=new Server(ip ,port);
QScriptValue sw = engine->newQObject( ss , QScriptEngine::ScriptOwnership);

return sw;

}

QScriptValue socket = myEngine.newFunction(socket_ctor);
myEngine.globalObject().setProperty("socket", socket);



How to launch some function (like: onConnect()) without using word 'connect' in this context, when my server get connected?


var sck=socket("localhost",1200);
sck.onConnect () {
.../do something - user defined handler for this event
}


I now how to launch 'global' function (which belongs no object), but how use it when function belongs to my object.

I repeate , i now how use it with word 'connect' with connecting c++ signal with script`s slot, but how just launch function?
Sorry for my english and thanx for answers...