How to set methods like __repr__ from the C++ side?
Dynamic Python binding for Qt Applications
Brought to you by:
florianlink,
marcusbarann
Pretty much the title, is there a way to do this? The examples show how to wrap C++ classes with the new_Class and delete_Class syntax as slots, but is it possible to override other python built-in functions?
Yes, there are some default Qt slot names that are looked for, but you have to register that your class supports the feature using an enum in registerCppClass (and you need to use the method on PythonQt::priv(), it has more arguments. Have a look at the generated wrappers, e.g. QPoint to see this in action. Regarding repr, PythonQt always looks for py_toString() slots.
Thanks Florian, that's very helpful! Works like a charm.
Last edit: Flower lady 2019-12-19
Hm, sounds like the destructor of your wrapper has a problem , at least
that is probably what the argument frame deletes on reset...
Do you do a qRegisterMetaType in your code? Using just the register macro
is not enough...
On Thu 19. Dec 2019 at 07:10, Flower lady fancyflowerlady@users.sourceforge.net wrote:
Hi Florian, sorry, I edited my post quickly but you found it before I did! There was a problem with the metatype registration, as you'd suggested. Thanks!