Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 6

Qt-interest Archive, May 2008
QtScript in 4.4.0 - returning QVariant from Q_INVOKABLE raises exception


Message 1 in thread

I have a QObject-derived class method declared as such:

Q_INVOKABLE QVariant result(EvalContext *ctx) const;

EvalContext and this particular class are both registered with 
qScriptRegisterMetaType<>(). When I call "result" from within a script, 
I get this error:

"uncaught exception at line 17: TypeError: not an object"

result =  QVariant(QString, "TypeError: not an object")

If I change result() to return a QString(), it works, but I want to be a 
QVariant. Any suggestions?

Incidentally, the error line is wrong. Line 17 would be the line if 
there were no empty lines in the script. With empty lines in my script 
code, the reported number is wrong.


-- 
 [ signature omitted ] 

Message 2 in thread

Paul Miller wrote:
> I have a QObject-derived class method declared as such:
> 
> Q_INVOKABLE QVariant result(EvalContext *ctx) const;
> 
> EvalContext and this particular class are both registered with 
> qScriptRegisterMetaType<>(). When I call "result" from within a script, 
> I get this error:
> 
> "uncaught exception at line 17: TypeError: not an object"
> 
> result =  QVariant(QString, "TypeError: not an object")

Oops - ignore this one! It does work! I was accidentally calling a 
broken script function from within the result() function, and the 
returned type was in fact wrong.

The line number problem is still there though.

-- 
 [ signature omitted ]