[Qt-interest] What QT version is this?

Scott Sibley sisibley at gmail.com
Thu Oct 15 09:46:19 CEST 2009


Ok, I got it. I had to add to Evaluator's constructor:

val = engine.newObject()

I just found out this isn't an actual function object, but rather just a
property getter/setter. I want all of the methods I'm providing to be
members of 'lcd' on the javascript side of things. Is that possible?

On Thu, Oct 15, 2009 at 2:09 AM, Scott Sibley <sisibley at gmail.com> wrote:

> Right. It's working now, except that the function's not available. Anything
> wrong with this?
>
> Evaluator::Evaluator() {
>     obj = new QObject();
>     QScriptEngine::QObjectWrapOptions opt;
>     QScriptValue objVal = engine.newQObject(val, obj,
> QScriptEngine::AutoOwnership, opt);
>     engine.globalObject().setProperty("lcd", objVal);
>     plugin_uptime_init(this);
> }
>
> QScriptValue Evaluator::Eval(const char *str) {
>     return engine.evaluate(str);
> }
>
> void Evaluator::AddFunction(const char *name,
>     QScriptValue (*func)(QScriptContext *ctx, QScriptEngine *eng)) {
>     QString key = name;
>     val.setProperty(key, engine.newFunction(func),
> QScriptValue::PropertyGetter);
> }
>
>
> Here's where I'm adding the function:
>
> void plugin_uptime_init(Evaluator *visitor) {
>     visitor->AddFunction("uptime", my_uptime);
> }
>
>
> I'm calling the method like this:
>
> std::cout << "Eval: " << (Eval("lcd.uptime()").toString().toStdString()) <<
> std::endl;
>
> And it prints:
>
> Eval: ReferenceError: uptime is not defined
>
>
> On Thu, Oct 15, 2009 at 1:54 AM, Rohan McGovern <rohan.mcgovern at nokia.com>wrote:
>
>> On Thursday 15 October 2009 08:48:23 ext Scott Sibley wrote:
>>
>> >
>> > Evaluator.cpp:26: error: passing 'const QScriptValue' as 'this' argument
>> of
>> >  'void QScriptValue::setProperty(const QString&, const QScriptValue&,
>> const
>> >  QFlags<QScriptValue::PropertyFlag>&)' discards qualifiers scons: ***
>> >  [Evaluator.o] Error 1
>> >
>> > void Evaluator::AddFunction(const char *name,
>> >     QScriptValue (*func)(QScriptContext *ctx, QScriptEngine *eng)) {
>> >     QString key = name;
>> >     obj.setProperty(key, engine.newFunction(func),
>> >  QScriptValue::PropertyGetter); // line 26 }
>> >
>>
>> > newFunction returns a const QScriptValue. I'm confused. Why does it
>> except
>> >  a non-const QScriptValue, but not the const?
>>
>> You're looking at the wrong QScriptValue.  The error is: "error: passing
>> 'const QScriptValue' as 'this' argument of ..."
>>
>> It's telling you: the problem is you're passing a const QScriptValue as
>> the
>> "this" argument to a QScriptValue member function not marked as const.  In
>> obj.setProperty(...), obj is the "this" argument.
>>
>> i.e., at line 26, `obj' is const.  If it's const then you can't set
>> properties
>> on it.
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091015/e2aa1256/attachment.html 


More information about the Qt-interest-old mailing list