Hi,
reading the forums I found at the moment QLists of custom objects are not supported, but I need to create one for an specific custom object so when we export it to python it behaves similarly to any of the current lists.
Could you please direct us to any example/info or place to see how to do it?
I suppose the way to do it may be to write akind of a wrapper to our QList<ourclass> but we are not being successful to do it.</ourclass>
Thanks in advance!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The easiest way is to use a QList of pointers to YourClass, then you only need to register YourClass with a wrapper/decorator. If you want a QList with YourClass as values, you need to register YourClass as a QMetaType and register a conversion callback for it, have a look how this is done for various list and map types in PythonQt.cpp (there is a macro that registers for vector, QList and QVector with your type). You still need a wrapper/decorator für YourClass for that case. But keep in mind that this will create copies of YourClass when you return or set such a list via a slot.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Look for PythonQtRegisterToolClassesTemplateConverterForKnownClass(QDate) and use it with your fully registered class. Your class needs to be copyable by PythonQt, so it needs to be registered as meta type or maybe it is also enough to have a copy constructor on your wrapper, not sure about that. Registering as QMetaType makes sense anyways.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
reading the forums I found at the moment QLists of custom objects are not supported, but I need to create one for an specific custom object so when we export it to python it behaves similarly to any of the current lists.
Could you please direct us to any example/info or place to see how to do it?
I suppose the way to do it may be to write akind of a wrapper to our QList<ourclass> but we are not being successful to do it.</ourclass>
Thanks in advance!
The easiest way is to use a QList of pointers to YourClass, then you only need to register YourClass with a wrapper/decorator. If you want a QList with YourClass as values, you need to register YourClass as a QMetaType and register a conversion callback for it, have a look how this is done for various list and map types in PythonQt.cpp (there is a macro that registers for vector, QList and QVector with your type). You still need a wrapper/decorator für YourClass for that case. But keep in mind that this will create copies of YourClass when you return or set such a list via a slot.
Thanks for the prompt response :) I will check that! ty!
Look for PythonQtRegisterToolClassesTemplateConverterForKnownClass(QDate) and use it with your fully registered class. Your class needs to be copyable by PythonQt, so it needs to be registered as meta type or maybe it is also enough to have a copy constructor on your wrapper, not sure about that. Registering as QMetaType makes sense anyways.