Menu

passing python byte array to C++ function

Help
2016-11-28
2020-12-19
  • Csaba Torda

    Csaba Torda - 2016-11-28

    Greetings,

    first of all I'd like to thank you for this great library, I find it really really useful.
    My problem is that I'd like to pass an array of bytes (python array('B') type) from python
    to a C++ function, but im not sure how to do that.

    Could you please help me with this topic ?

    Thank you in advance.

     
  • Florian Link

    Florian Link - 2016-11-28

    I think you need to use QByteArray in your C++ method to get access to the Python bytes.

     
  • Florian Link

    Florian Link - 2016-11-28

    Alternatively, if you don't want to make a copy of the Python bytes, you can use a pointer to PyObject in your signature, but then you would need to use the Python C-API to check if the passed object is PyBytes and to extract the data.

     
  • Csaba Torda

    Csaba Torda - 2016-11-28

    if i just use QByteArray, the interpreter gives the following error:

    python_qt.py", line 13, in entry
    req.my_cpp_func([0xFF])
    ValueError: Called my_cpp_func() -> void with wrong number of arguments: ([255],) 
    
     

    Last edit: Csaba Torda 2016-11-28
  • foghua

    foghua - 2020-12-19

    you need use a python string as the input parameter

     

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.