[Qt-interest] Registering a pointer type with qScriptRegisterMetaType
Mike Filonov
mikefilonov at gmail.com
Thu Feb 5 13:23:52 CET 2009
Hi
I want to add to QtScript my function (named ObjectModel) that
returns a pointer to an instance of my class (Document)
An error returns when i'm calling it in qt-script:
>TypeError: cannot call ObjectModel(): unknown return type `Document*' (register the type with qScriptRegisterMetaType())
So, in order to have this function to work properly i have to write a
lot of code:
>typedef Document* pDocument
>Q_DECLARE_METATYPE(Document*)
>QScriptValue pDocumentToScriptValue(QScriptEngine *engine, const pDocument & obj){
> QScriptValue qsObj = engine->newQObject(obj);
> return qsObj;
>}
>void pDocumentFromScriptValue(const QScriptValue &, pDocument & obj){
> return;
>}
>...
>qScriptRegisterMetaType( engine, pDocumentToScriptValue, pDocumentFromScriptValue );
I have a compilating error if "Document*" is used instead of "pDocument"
I'm wondering is there more simple way to do this? May be i miss
something in a philosophy of Qt and it is better not to return
pointer, but reference?
More information about the Qt-interest-old
mailing list