Menu

pythonic way to access Cpp Wrapper

Help
2015-11-18
2015-11-18
  • Joerg Kreuzberger

    Hi!

    Wrapping my C++ Classes with registerCPPClass and PythonQt works well.
    But i want to access my Class the pythonic way.
    E.g. if it is implementing a list (must not be QList)
    it should support the default operations like len(), [] operators and so on.

    if i provide e.g. a len() funtion in the wrapper, i cannot call
    len(myobject). i can only call myobject.len()

    SWIG support this with special functions like
    getitem(int i) { return self->testBit(i); }
    void setitem(--)
    int len()

    What is the PythonQt way to achieve this?

     
  • Joerg Kreuzberger

    Sorry, the code blocks were formated..

      bool __getitem__(int i) {  }
      void __setitem__(int i, ...) { }
      int __len__() {  }
    
     
  • Florian Link

    Florian Link - 2015-11-18

    I don't support that yet... I recently added support for mappings, but not yet for sequences.
    If I add it, it will still require a special type slot flag on registerCppClass, just having the correct slots is not enough.

     

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.