Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. trying to create a python binding for a C++ Qwidget
Forum Update on Monday, May 27th 2025

trying to create a python binding for a C++ Qwidget

Scheduled Pinned Locked Moved Unsolved Qt for Python
7 Posts 3 Posters 701 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jan Menssen
    wrote on 12 Aug 2024, 21:22 last edited by
    #1

    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.xml

    Can someone help me. I guess I should use the -F option ? Or is something else wrong

    Kind regards - jan

    1 Reply Last reply
    0
    • J Jan Menssen referenced this topic on 12 Aug 2024, 21:40
    • F Offline
      F Offline
      friedemannkleint
      wrote on 13 Aug 2024, 07:55 last edited by
      #2

      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.

      J 1 Reply Last reply 13 Aug 2024, 08:23
      0
      • F friedemannkleint
        13 Aug 2024, 07:55

        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.

        J Offline
        J Offline
        Jan Menssen
        wrote on 13 Aug 2024, 08:23 last edited by
        #3

        @friedemannkleint
        Thank you for you answer

        After 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

        1 Reply Last reply
        0
        • F Offline
          F Offline
          friedemannkleint
          wrote on 13 Aug 2024, 20:46 last edited by
          #4

          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/ ).

          J 1 Reply Last reply 14 Aug 2024, 09:23
          0
          • F friedemannkleint
            13 Aug 2024, 20:46

            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/ ).

            J Offline
            J Offline
            Jan Menssen
            wrote on 14 Aug 2024, 09:23 last edited by Jan Menssen
            #5

            @friedemannkleint

            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
            ??

            1 Reply Last reply
            0
            • F Offline
              F Offline
              friedemannkleint
              wrote on 14 Aug 2024, 12:54 last edited by
              #6

              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.

              1 Reply Last reply
              0
              • M Offline
                M Offline
                MonkeyBusiness
                wrote on 19 Feb 2025, 09:11 last edited by
                #7

                @friedemannkleint hi fried, I have question, does the example's python qwidget able to dock onto a c++ qmainwindow?

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved