Emulation of properties for composite objects
Dynamic Python binding for Qt Applications
Brought to you by:
florianlink,
marcusbarann
Hi, Florian!
I'm working on a scripting interface for the object representation of XML documents. In this regard, there is a need to emulate the properties of objects, whose members are other objects (composite objects), for example:
In a Python script to access a member of a nested object should be as follows:
py> q = MyDoc ()
py> q.elem.attr2 = "value"
py> print q.elem.attr2
Class decorators, obviously, must be determined as follows:
However, since the method MyDocWrapper::py_get_elem () returns a value (not a reference), the assignment is performed for a temporary object of MyElem. Therefore, the result of the print statement in the above script example is an empty string.
Reading of attr2 member is performed correctly (understand why).
Question: is there a way to ensure the desired behavior of the properties for the member elem?
Sincerely,
Sergey.
Sounds like you should do:
MyElem* py_get_elem (MyDoc * o) {return &(o-> elem);}
instead, so that you return the exact MyElem object to Python, instead of a copy.
I am ashamed to admit, I tried only the reference and got an error during script execution.
Of course, one could assume that in such a wonderful library there should not be similar drawbacks. Thanks and successes!
Sincerely,
Sergey.
Thanks!
The problem with references is that Qt's moc compiler doesn't like them as return values on slots, neither const & nor &,
so one has to use pointers instead.
Regards,
Florian