Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How add python class to C++ project?
Forum Updated to NodeBB v4.3 + New Features

How add python class to C++ project?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
8 Posts 3 Posters 751 Views 1 Watching
  • 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.
  • R Offline
    R Offline
    realroot
    wrote on last edited by
    #1

    I have a QML app with a small main.cpp there are no C++ classes.

    I made it with Qt Creator.

    How add python class to the project?

    1 Reply Last reply
    0
    • R realroot

      I used:

      /usr/lib/qt6/rcc src/resources.qrc -o src/resources.py
      

      But you need to specify -g python too.

      R Offline
      R Offline
      realroot
      wrote on last edited by
      #8

      Using pyotherside you can use python in QML with C++.

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #2

        Hi,

        What do you want to do with Python ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        R 1 Reply Last reply
        0
        • SGaistS SGaist

          Hi,

          What do you want to do with Python ?

          R Offline
          R Offline
          realroot
          wrote on last edited by
          #3

          @SGaist Hi,
          I am thinking about adding some backend.

          To save/edit/import etc. configuration.

          JonBJ 1 Reply Last reply
          0
          • R realroot

            @SGaist Hi,
            I am thinking about adding some backend.

            To save/edit/import etc. configuration.

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #4

            @realroot
            So far as I know mixing Python with C++ is (relatively) not so straightforward. If you want to use Python and haven't written any C++ have you considered just using Python with QML, no C++?

            R 1 Reply Last reply
            0
            • JonBJ JonB

              @realroot
              So far as I know mixing Python with C++ is (relatively) not so straightforward. If you want to use Python and haven't written any C++ have you considered just using Python with QML, no C++?

              R Offline
              R Offline
              realroot
              wrote on last edited by
              #5

              @JonB
              Yes I thought about that.
              Do I make a app.pyproject?
              I tried that but Qt Creator didn't show any files besides app.pyproject.
              Maybe I missed something.

              If I use C++ it will be easier to make a binary with all files embedded I think.
              And I can keep the current state.

              For example this app https://gitlab.com/mx-moment/moment has a main.cpp and uses mostly python.
              Not sure how.

              R 1 Reply Last reply
              0
              • R realroot

                @JonB
                Yes I thought about that.
                Do I make a app.pyproject?
                I tried that but Qt Creator didn't show any files besides app.pyproject.
                Maybe I missed something.

                If I use C++ it will be easier to make a binary with all files embedded I think.
                And I can keep the current state.

                For example this app https://gitlab.com/mx-moment/moment has a main.cpp and uses mostly python.
                Not sure how.

                R Offline
                R Offline
                realroot
                wrote on last edited by
                #6

                I made the project use python instead of C++.

                I converted resource.qrc to resource.py but I have error when I run the app:

                Starting /path/app/venv/bin/python -u main.py...
                Traceback (most recent call last):
                  File "/path/app/src/main.py", line 8, in <module>
                    import resources
                  File "/path/app/src/resources.py", line 121514
                    QT_RCC_MANGLE_NAMESPACE0(name), QT_RCC_MANGLE_NAMESPACE0(QT_NAMESPACE))
                                                                                          ^
                SyntaxError: unmatched ')'
                

                The file resource.py shows the local path but it should be upload with the app code and that does not seem correct.

                R 1 Reply Last reply
                0
                • R realroot

                  I made the project use python instead of C++.

                  I converted resource.qrc to resource.py but I have error when I run the app:

                  Starting /path/app/venv/bin/python -u main.py...
                  Traceback (most recent call last):
                    File "/path/app/src/main.py", line 8, in <module>
                      import resources
                    File "/path/app/src/resources.py", line 121514
                      QT_RCC_MANGLE_NAMESPACE0(name), QT_RCC_MANGLE_NAMESPACE0(QT_NAMESPACE))
                                                                                            ^
                  SyntaxError: unmatched ')'
                  

                  The file resource.py shows the local path but it should be upload with the app code and that does not seem correct.

                  R Offline
                  R Offline
                  realroot
                  wrote on last edited by
                  #7

                  I used:

                  /usr/lib/qt6/rcc src/resources.qrc -o src/resources.py
                  

                  But you need to specify -g python too.

                  R 1 Reply Last reply
                  0
                  • R realroot

                    I used:

                    /usr/lib/qt6/rcc src/resources.qrc -o src/resources.py
                    

                    But you need to specify -g python too.

                    R Offline
                    R Offline
                    realroot
                    wrote on last edited by
                    #8

                    Using pyotherside you can use python in QML with C++.

                    1 Reply Last reply
                    0
                    • R realroot has marked this topic as solved on

                    • Login

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