Menu

passing a numpy object to decorator creator

Help
tom
2017-06-01
2017-06-01
  • tom

    tom - 2017-06-01

    I have a c++ class nPhysD and I'm trying to have a creator based on a numpy array.

    Here is the wrapper defining the new_ python creator taking PyObject as argument:

    class nPhysPyWrapper : public QObject {
        Q_OBJECT
    
    public slots:
    [...]
        nPhysD* new_nPhysD(PyObject* my_py_obj){
        //do something
        }
    }
    

    But the creator doesn't get called and from within () Python I get:

    ValueError: Could not find matching overload for given arguments:
    (array([[ 10.,  11.,  10., ...,  11.,  11.,  11.],
           [ 11.,  11.,  11., ...,  11.,  11.,  11.],
           [ 11.,  11.,  11., ...,  11.,  11.,  11.],
           ..., 
           [ 11.,  11.,  11., ...,  10.,  11.,  11.],
           [ 11.,  11.,  11., ...,  11.,  11.,  11.],
           [ 11.,  11.,  11., ...,  11.,  11.,  11.]]),)
     The following slots are available:
    nPhysD(PyObject my_py_obj) -> nPhysD
    [...]
    

    I tried by replacing Pyobject* with PyArrayObject* but I get the same error.

    How do I do?

     
  • Florian Link

    Florian Link - 2017-06-01

    I will have to try that myself, it should work... It has to be PyObject pointer, since that is the name that is checked in PythonQt, so PyArrayObject will surely fail.

     
  • Florian Link

    Florian Link - 2017-06-01

    The following worked for me:

    QObject* new_QObject(PyObject* test) { std::cout << "called" << std::endl; return new QObject(); }
    

    And I can call QtCore.QObject(somePythonObject). The important thing is that your method needs to return a new object, if it returns NULL you will get an error.

     
  • tom

    tom - 2017-06-01

    wow, I missed that you need to actually return something (I still belive ther's som magic behind the way pytohnqt scrapes the metasystem).
    I did put nullptr to do some tests before returing a proper object.

    Now it works.

    Thanks a million.

     

Log in to post a comment.