Using constructor with WrapperFactory
Dynamic Python binding for Qt Applications
Brought to you by:
florianlink,
marcusbarann
Hello!
I master PythonQt by means of examples, use Qt SDK 1.1 for Windows, PythonQt 2.0.1.
I can not force to work Wrapper Factory in example PyCPPWrapperExample. At execution of a script examle.py the error stands out:
If the object is created not by the constructor, and with the slot of auxiliary object, for example, how is made in a test example PythonQtTestSlotCalling::testCppFactory():
it works. But all the same, the object created by the constructor, doesn't use WrapperFactory.
What do I don't understand?
Yours faithfully,
Sergey.
Hi Sergey,
the wrapper factory approach is quite old and nowadays we typically use decorators.
I updated to examples shortly after the 2.0.1 release, maybe testing the SVN trunk version fixes the problem?
On the otherhand, I am not sure if constructors ever worked together with wrapper factories, I would use decorator classes instead! Another workaround is to use a factory method instead of a constructor (just a slot that returns the new object, this can even be a static decorator, so that it is a factory method on the class)
regards,
Florian
regards,
Florian
Hello, Florian!
Thanks for the help! I will try your councils, of course.
I will explain, why I use the Factory approach. I need to wrap up mine C++ classes which have been not QObject derived. Thus I want to use Qt properties that in python scripts to write so: obj.attr = value. And even so: obj.subobj.attr = value.
The slots of decorators need to pass a pointer to the wrapped object as the first argument. Hence, in the decorators I can not realize property Qt. Or I am mistaken?
Yours faithfully,
Sergey.
Hi Sergey,
that is true. But you can emulate properties in the decorators like this:
public slots:
void py_set_yourProperty(YourClass* cpp, YourTypeOrQVariant value) { … }
YourTypeOrQVariant py_get_yourProperty(YourClass* cpp) { … }
This will add a python property named yourProperty to your wrapped C++ class.
You can either use concrete types or QVariant for the value of the property.
regards,
Florian
Many thanks! I will try.
Yours faithfully,
Sergey.
It works! It is documentary feature?
Yours faithfully,
Sergey.
No, I actually forgot to document it, since I added it mainly for QStyleOption public member wrapping done by the code generator.
In my opinion, it is very useful feature. It saves the whole line of a code on each property! It is necessary to document it, that there was a confidence that in the future it will be supported.
Thanks for library! Successes!
Yours faithfully,
Sergey.