trying to create a python binding for a C++ Qwidget
-
Hi
I created in C++ a subclass of QStatusbar which compiles/links and executes as it should be
Now I want to make bindings for Python. I use Shiiboken6 together with the examples provided from Qt.
Creating the SAMPLING_LIBRARY (as it is called by Qt example, I think this is just as standard dynamic library seems to work, the *.dylib file (I'm working on a Mac) is created
I use Cmake for compiling and building and in Cmake I call Shiboken6 as in the QT examples.
In the bindings.h file I include "statusbar.h", the header file for the statusbar class. This header file contains <QStatusBar>Shiboken gives an error running ApiExctractor and later during a try of the build I got an error "opt/homebrew/lib/QtWidgets.framework/Headers/qstatusbar.h:6:10: fatal: 'QtWidgets/qtwidgetsglobal.h' file not found)
I don't think this is a compiler/build problem. The standard SAMPLING_LIBRARY builds and the same statusbar.h is included which contains <QStatusBar>. I Guess the Shiboken error results in the error in compiling/linking the wrapper files. (bindings.h is mentioned as the source of the error and bindings.h is used in Shiboken)
I already figured out in Shibobken an additional -I statement should be placed for every include directory and added all subfolder of QtWigets separate without solving the problem.
******These are the shiboken option I use
shiboken: Error running ApiExtractor.
[build] Command line:
[build] "--generator-set=shiboken"
[build] "--enable-parent-ctor-heuristic"
[build] "--no-implicit-conversions"
[build] "--enable-return-value-heuristic"
[build] "--use-isnull-as-nb_nonzero"
[build] "--avoid-protected-hack"
[build] "--lean-headers"
[build] "-I/Users/jan/Library/CloudStorage/OneDrive-Personal/my projects/2024 physiomon/c-sources/statusbar"
[build] "-I/Users/jan/library/CloudStorage/OneDrive-Personal/my projects/2024 led"
[build] "-I/opt/homebrew/lib/QtWidgets.framework/Headers"
[build] "-I/opt/homebrew/lib/QtWidgets.framework"
[build] "-T/Users/jan/Library/CloudStorage/OneDrive-Personal/my projects/2024 physiomon/shiboken interface"
[build] "--output-directory=/users/jan/documents/build"
[build] "/Users/jan/Library/CloudStorage/OneDrive-Personal/my projects/2024 physiomon/shiboken interface/bindings.h"
[build] "/Users/jan/Library/CloudStorage/OneDrive-Personal/my projects/2024 physiomon/shiboken interface/bindings.xmlCan someone help me. I guess I should use the -F option ? Or is something else wrong
Kind regards - jan
-
-
Have you checked the widget binding example https://doc.qt.io/qtforpython-6/examples/example_widgetbinding_widgetbinding.html ?
It is advisable to follow the convention #include <QtWidgets/QStatusBar> (used in Qt source) for bindings.
-
@friedemannkleint
Thank you for you answerAfter posting I checked all the examples given by Qt / Shiboken. I discovered a number of options for shiboken
- F
- --force-process-system-include-paths
which I currently doesn't understand but sometimes they are used.
Also for me It is not clear I should link to the standard C libraries or the Python libraries.Unfortunetaly, the CMakelists.txt file is not given in the example you mentioned. Do you know the example is also in Github or so ?
kind regards - jan
-
The example is in the repository ( https://code.qt.io/cgit/pyside/pyside-setup.git/tree/examples/widgetbinding ) or available as wheel ( https://pypi.org/project/PySide6-Examples/ ).
-
Dear Friedemann
Thank you for your answer, I downloaded the example and run this on a Mac (M3 system Qt ver 6.6.1) and a Windows machine (win10, QT ver 7.6)
-
On the windows machine the example works (only when build in release, I think I did not install python_d)
-
On the Mac, I got an error and almost the same error as in my first post : tCore/qglobal.h file not found. If I ommit this include file, the next error 'QtWidgets/QWidget' file is not found.
Both errors are in fact generated by Shiboken/building the bindings library. So I guess there is something wrong with the Qt folders that are included. (I never see this error during standard compilation to an executable) and checked these folders (part of the Shiboken option)
Windows
-IC:/Qt/6.7.2/msvc2019_64/include/QtWidgets;
-IC:/Qt/6.7.2/msvc2019_64/include;Mac
"-I/opt/homebrew/lib/QtWidgets.framework/Headers"
"-I/opt/homebrew/lib/QtWidgets.framework"
"--framework-include-paths=/opt/homebrew/lib/QtCore.framework/Versions"As I expect (reading the comments in the Cmake file, the framework option is included).
As far as I know (long time ago) I installed only the Qt libs on the Mac with the "brew install qt" command and installed Qt on windows with the QT installer/maintenance tool ? Could this be the problem ?
Also the frameworks used on a Mac are not familiar for me.Please could you help me. Currently I think installing Qt using the maintenance tool seems the best option
Kind regards - jan
ps. I uninstalled Qt with homebrew and installed using the standard Qt installation / maintenance tool. The same error arises. Include path are changed of course
?? -
-
This is hard to remote-diagnose; you really have to look at the include paths passed to shiboken. The standard Qt installation / maintenance tool should indeed be better.