On Thursday 02 December 2010 13:32:00 Jukka Välimaa wrote:
> Hi all,
> 
> I have a question about QScriptEngine. I want to insert objects that I
> define in python into script context so that their methods can be called
> from evaluated scripts. The problem I have right now is that properties of
> these objects are not available in the script environment.
> 
> From my reading of the documentation I concluded that it might be because
> I'm not running Q_Object macro. However, I don't know if there is a way of
> replicating what that macro does while sticking to Python.

QtScript can only access the properties found in the object meta-object and to 
export properties to the object meta-object you need to create them using the 
QtCore.Property function. e.g.

class Foo (QtCore.QObject):
        def getA(self):
                return self._a;
        def setA(self, value):
                self._a = value

        a = QtCore.Property(getA, setA)

> An alternative way to do this would be to populate the object with function
> properties one by one. Unfortunately, it seems like QScriptEngine API is
> missing newFunction-method.

This is a missing feature, it hasn't implemented yet because newFunction 
expects a C function pointer and the binding can't create C function at 
runtime, however we can silent use QScriptEngine::FunctionWithArgSignature and 
use the additional void pointer to do some voodoo and make it work and 
functional.

In other words... file a bug about it =]

> Does anybody have any suggestion about what I could do to run methods from
> python objects I insert into script environment?

Set those methods as slot using the @Slot decorator, so they will be 
registered into the object QMetaObject and QtScript will see them.

> Regards,
> Jukka Välimaa

-- 
Hugo Parente Lima
INdT - Instituto Nokia de Tecnologia

Attachment: signature.asc
Description: This is a digitally signed message part.

_______________________________________________
PySide mailing list
[email protected]
http://lists.openbossa.org/listinfo/pyside

Reply via email to