pythonqt icon indicating copy to clipboard operation
pythonqt copied to clipboard

Bind class that accepts object from external package

Open kerim371 opened this issue 4 years ago • 0 comments

Hi,

I have simple class:

#ifndef __qColadaTreeTEST_h
#define __qColadaTreeTEST_h

// Qt includes
#include <QTreeView>

// Colada includes
#include "qColadaAppExport.h"

// h5gt includes
#include <h5gt/H5File.hpp>  // has python bindings using pybind11 

class Q_COLADA_APP_EXPORT qColadaTreeTEST : public QTreeView {
  Q_OBJECT

public:
  explicit qColadaTreeTEST(QWidget *parent = nullptr);
  ~qColadaTreeTEST() = default;

public slots:
  bool addH5File(h5gt::File file);  // file -  is of type `h5gt::File` -> it has python bindings
};

#endif

as you can see it accepts h5gt::File file wich is not Qt based C++ class. But h5gt library has python bindings done with pybind11 so it is accessible from python.

When qColadaTreeTEST is binded via PythonQt I cannot call addH5File with h5gt.File argument as it gives me an error:

import qColadaAppPythonQt
q = qColadaAppPythonQt.qColadaTreeTEST()

from h5gtpy import h5gt
file_name = 'D:/test.h5'
file = h5gt.File(file_name, h5gt.OpenFlag(h5gt.ReadWrite | h5gt.Create | h5gt.Truncate))

q.addH5File(file)   # here I get the following error:

Traceback (most recent call last):
  File "<console>", line 1, in <module>
ValueError: Called addH5File(h5gt::File file) -> bool with wrong arguments: (<h5gtpy._h5gt.File object at 0x00000285128901F0>,)

How to tell PythonQt that h5gt::File C++ class is the same as h5gtpy._h5gt.File in Python?

kerim371 avatar Jul 20 '21 10:07 kerim371