[Qt-interest] Problem about QScript
Zhongmiao Li
mars.leezm at gmail.com
Mon Dec 13 16:23:29 CET 2010
Thanks for your help, dear Mr. Sean ans Mr.Shang, your suggesstion give me
some new thought.
I tried m_scriptEngine->globalObject().setProperty( "log", logObj ), but
still it does not work.
In fact, in the example classes from Qt, only
return m_engine->newQObject(object, QScriptEngine::QtOwnership,
QScriptEngine::PreferExistingWrapperObject
| QScriptEngine::ExcludeSuperClassContents);
is enough. And the developer of QtJambi also said that QScript is not
fully tested in the contemporarily
newest version.
This is my JS program.
var canvas = document.getElementById('tutorial');
var ctx = canvas.getContext('2d');
ctx.beginPath();
ctx.moveTo(25,25);
ctx.lineTo(105,25);
ctx.lineTo(25,105);
ctx.fill();
ctx.beginPath();
ctx.moveTo(125,125);
ctx.lineTo(125,45);
ctx.lineTo(45,125);
ctx.closePath();
ctx.stroke();
It fails in the second line, but I think in the first line does not return a
valid variable. Then I tried to remove the first two lines and added the
following lines in my program.
appcontext= engine.newQObject( context,
QScriptEngine.ValueOwnership.QtOwnership,
QScriptEngine.QObjectWrapOption.ExcludeSuperClassContents);
engine.globalObject().setProperty("ctx", appcontext);
Although I did not seen anything was painted on my screen, but at least
there is no more parsing error reading JavaScript!
So as far as I'm concerned, the problem can be concluded as:
*Creating a variable in the JAVA program by setting property is OK, but
there is something wrong with the transmisson of variable between JS and
Java( Or just maybe this function*
* is not implemented in Jambi? ).*
Could you provide some further ideas about this? I'm new to QScript. Thanks
a lot!!
On Mon, Dec 13, 2010 at 3:54 AM, Sean Harmer <
sean.harmer at maps-technology.com> wrote:
> 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
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
--
Best regards
Li Zhongmiao
Digital Media, College of Computer Science, Zhejiang University
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20101213/c85d8253/attachment.html
More information about the Qt-interest-old
mailing list