Menu

Creating a custom object QList

Help
2019-12-06
2019-12-07
  • Miguel Angel

    Miguel Angel - 2019-12-06

    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!

     
  • Florian Link

    Florian Link - 2019-12-06

    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.

     
  • Miguel Angel

    Miguel Angel - 2019-12-06

    Thanks for the prompt response :) I will check that! ty!

     
  • Florian Link

    Florian Link - 2019-12-07

    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.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.