[Qt-interest] Problem about QScript

Sean Harmer sean.harmer at maps-technology.com
Mon Dec 13 12:54:34 CET 2010


Hi,

On Monday 13 December 2010 11:15:47 Zhongmiao Li wrote:
> Thank you!  In fact I'm writing in QtJambi and I have turned to QtJambi
> mailing list, but they are not familiar with QScript.
> My code is as following:
> 
> QScriptValue tmp=engine.newQObject(object,
> QScriptEngine.ValueOwnership.QtOwnership,
>                
> QScriptEngine.QObjectWrapOption.PreferExistingWrapperObject,
> QScriptEngine.QObjectWrapOption.ExcludeSuperClassContents);
> 
> boolean isObj= tmp.isObject();
> boolean isUNDefined=tmp.isUndefined();
>         return tmp;
> 
>  I have checked isObj, it's true;  and I also checked isUNDefined, it's
> false.
> 
> So do you know if there is some other possibility that causes this problem?
>  Thanks very much!

Well you are still not showing how you expose this object to the scripting 
side. All we know is that you have created a QScriptValue from an object. 
Somehow you need to expose this to your scriptengine.

In C++ I use this pattern to expose the object as a global variable for 
example:

m_scriptableLog = new ScriptableLogWidget( m_log, m_scriptEngine );
QScriptValue logObj = m_scriptEngine->newQObject( m_scriptableLog );
m_scriptEngine->globalObject().setProperty( "log", logObj );

I can then access this object via the variable name "log" in my scripts for 
this particular application.

HTH,

Sean



More information about the Qt-interest-old mailing list