Skip to content

QtScript 105

Monday, 12 February 2007  |  rich

I've done a bit more stuff with QtScript in order to keep up with the changes in the Qt snapshots. The API has changed a bit to make things more consistent, and I've updated the demo code I had to work with the new version. The changes to support the new API were pretty simple, and basically amount to using factory methods on QScriptEngine to create your script values. The cast operator qscript_cast has also been renamed and is now qscriptvalue_cast, but it works as before.

I also took the oportunity to fix an issue with the code - originally, it was possible for scripts to break factory methods I was adding for QWidgets by changing the functionName property. I've now changed the code to look like this:

 fun.setProperty( QString("functionName"), name,
	 QScriptValue::ReadOnly | QScriptValue::Undeletable | QScriptValue::SkipInEnumeration );
which makes it so that this property is read-only from javascript and can't be deleted or enumerated using a for loop.

The code can be downloaded from http://xmelegance.org/devel/qscriptdemo5.tar.gz.