[Qtscript-bindings] signals/slots overriding
Peter Zhou
peterzhoulei at gmail.com
Wed Aug 13 11:02:14 CEST 2008
how can I override a signal or a slot in a script?
for example,
engine->setDefaultPrototype(
qMetaTypeId<ScriptableServiceScript*>(), QScriptValue() );
const QScriptValue ctor = engine->newFunction(
ScriptableServiceScript_prototype_ctor );
const QScriptValue populate = engine->newFunction(
ScriptableServiceScript_prototype_populate );
ctor.property( "prototype" ).setProperty( "populate", populate );
engine->globalObject().setProperty( "ScriptableServiceScript", ctor );
qScriptConnect( this, SIGNAL( populate( QString, int, int,
QString, QString ) ), QScriptValue() ,populate );
here's the code written in C++ which connects the populate signal to
the prototype_populate method
then define a child class in a script:
function CoolStream()
{
ScriptableServiceScript.call( this, "Cool Streams", 1, "List of
some high quality radio streams", "Some really cool radio streams,
hand picked for your listening pleasure by your friendly Amarok
developers", false );
}
CoolStream.prototype.populate = function( serviceName, level,
parent_id, callbackData, filter )
{
print( " Populating station level..." );
//add the station streams as leaf nodes
for ( i = 0; i < stationArray.length; i++ )
{
name = stationArray[i].name;
url = stationArray[i].url;
html_info = "A cool stream called " + name;
this.insertItem( serviceName, 0, name, html_info, url,
callback_string );
this.donePopulating( serviceName, parent_id );
}
}
script = new CoolStream();
In this case, the populate method in the script will never be called
Thanks,
--
Peter
-------------------------------
http://www.peterzl.net/
More information about the Qtscript-bindings
mailing list