[PySide] Python bindings for Qt/C++ library (advice needed on best practices)
info at mycontent.gr
info at mycontent.gr
Thu Jul 19 02:10:35 CEST 2018
first of all congratulations and thanks to the PySide2 team for a great
After going through the blog post at
http://blog.qt.io/blog/2018/05/31/write-python-bindings/ on creating
Python bindings for a C++ library with Shiboken, a few questions arise
when thinking about a bigger/real-life project. I suspect these
questions will come up frequently as people try to build Python bindings
for their projects, so I would like to volunteer to collect the answers
that I hope to get from this mailing list into a tutorial-style document
(if the team is interested in this!)
Suppose that we have a Qt-based C++ library, for which we would like to
create Python bindings.
Many library classes are subclasses of QObject. There are several
methods accepting QString arguments and returning QLists, QHashes,
QMaps, as well as pointers to the library’s objects.
Suppose that the library uses QtSql and QtXml (and many elements of
QtCore) internally, but these objects need not be exposed to the user.
In most use cases, the users of the bindings will not need the Qt user
interface classes, as they will be writing automation scripts. The
library itself does not depend on QtGui, QtWidgets etc.
What would be the best course of action:
1. Write a thin interface layer to the library using only C++ primitives
and STL types, like std::string, std::list, so that all interfaces that
will be exposed to Python accept and return standard library constructs?
2. Create Python bindings with Qt objects as arguments?
In the first case, how can we keep the dependencies for library users to
a minimum? QtCore, QtSql and QtXml are necessary for the functioning of
the library, but the Python bindings of these Qt libraries, normally
should not be necessary (is this correct?).
In the second case, how can we package the library in such a way that
the required PySide2 dependencies are installed automatically
(preferably using pip)? How can we keep the dependencies to a minimum?
Thank you very much for your time!
More information about the PySide