Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Calling Python from QT C++
Forum Updated to NodeBB v4.3 + New Features

Calling Python from QT C++

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 3 Posters 3.4k 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.
  • C Offline
    C Offline
    ChrisW
    wrote on last edited by ChrisW
    #1

    Hi everyone,

    I love my C++ and Python. C++ gives me the low-level ability, while Python gives me the high-level. Now, the headache, is trying to integrate both of these languages together. I ran into multiple deadends on YouTube and also seeing a lot of videos that are very, very long. Right now, I just need to integrate the two languages. I saw a package that is supposedly work with QT 4.6.1, however, the headache with that is that it is calling the latest Qt that I have, which is 5.8, I believe. I really don't want to uninstall it.

    Another thing, it would be great if I knew how to integrate Python with C++ in Visual Studio 2017.

    Thanks ahead for your time, and if you're able to redirect me to an article that is still relevant today, please feel free to point me in that direction without much comment. I know life can be busy. And again, I want to use C++ as my main language and use Python whenever there is a task that Python does better. Also, being able to use the modules of Python is important too.

    jsulmJ 1 Reply Last reply
    0
    • C ChrisW

      Hi everyone,

      I love my C++ and Python. C++ gives me the low-level ability, while Python gives me the high-level. Now, the headache, is trying to integrate both of these languages together. I ran into multiple deadends on YouTube and also seeing a lot of videos that are very, very long. Right now, I just need to integrate the two languages. I saw a package that is supposedly work with QT 4.6.1, however, the headache with that is that it is calling the latest Qt that I have, which is 5.8, I believe. I really don't want to uninstall it.

      Another thing, it would be great if I knew how to integrate Python with C++ in Visual Studio 2017.

      Thanks ahead for your time, and if you're able to redirect me to an article that is still relevant today, please feel free to point me in that direction without much comment. I know life can be busy. And again, I want to use C++ as my main language and use Python whenever there is a task that Python does better. Also, being able to use the modules of Python is important too.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @ChrisW Check https://docs.python.org/2/extending/embedding.html

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      C 1 Reply Last reply
      4
      • jsulmJ jsulm

        @ChrisW Check https://docs.python.org/2/extending/embedding.html

        C Offline
        C Offline
        ChrisW
        wrote on last edited by
        #3

        @jsulm

        OMG! So sorry that I'm late to the party. I didn't see this post until now and never got an alert. Thanks and I will make sure to look over this documentation.

        1 Reply Last reply
        0
        • thamT Offline
          thamT Offline
          tham
          wrote on last edited by
          #4

          I use boost python to glue c++ and python before, but this solution need the user to install python on their pc.
          Another solution is write a server by python and use Qt to communicate with it, this way I can package the python
          as a standalone application.

          1 Reply Last reply
          0
          • C Offline
            C Offline
            ChrisW
            wrote on last edited by
            #5

            Yes Jsulm, I was able to get Boost working on Visual Studio. Unfortunately, Boost's documentation said that the implementation is limited without the Python API. So I guess they are talking about the Python-Dev package. Unfortunately, I don't really know how to link that package. It is 3 steps that are required for using a third-party library or whatever, but I don't know what to type into the input part of the 3 steps.

            Visual Studio is now recognizing the Python.h file, but I get a compiler error:

            Severity Code Description Project File Line Suppression State
            Error LNK1104 cannot open file 'python27_d.lib' Python-Dev c:\Users\chris williams\documents\visual studio 2015\Projects\Python-Dev\Python-Dev\LINK 1

            So I decided to type in python27_d.lib as a value for the input.

            Just in case if you're not familiar with the 3 steps:

            http://stackoverflow.com/questions/35008426/link-3rd-party-library-in-visual-studio

            Also, I'm using python-dev-2.7.8-src
            if that helps and I cannot find any .lib files.

            My understanding is that I need the Python.h file. The examples online on using C++ are straight forward, but they all assume that you have access to that header.

            Thanks

            jsulmJ 1 Reply Last reply
            0
            • C ChrisW

              Yes Jsulm, I was able to get Boost working on Visual Studio. Unfortunately, Boost's documentation said that the implementation is limited without the Python API. So I guess they are talking about the Python-Dev package. Unfortunately, I don't really know how to link that package. It is 3 steps that are required for using a third-party library or whatever, but I don't know what to type into the input part of the 3 steps.

              Visual Studio is now recognizing the Python.h file, but I get a compiler error:

              Severity Code Description Project File Line Suppression State
              Error LNK1104 cannot open file 'python27_d.lib' Python-Dev c:\Users\chris williams\documents\visual studio 2015\Projects\Python-Dev\Python-Dev\LINK 1

              So I decided to type in python27_d.lib as a value for the input.

              Just in case if you're not familiar with the 3 steps:

              http://stackoverflow.com/questions/35008426/link-3rd-party-library-in-visual-studio

              Also, I'm using python-dev-2.7.8-src
              if that helps and I cannot find any .lib files.

              My understanding is that I need the Python.h file. The examples online on using C++ are straight forward, but they all assume that you have access to that header.

              Thanks

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @ChrisW You should ask @tham about boost python - I never used it. You not only need Python.h header file but the library as well - it should be in the normal python installation under PYTHON/libs.

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              C 1 Reply Last reply
              1
              • jsulmJ jsulm

                @ChrisW You should ask @tham about boost python - I never used it. You not only need Python.h header file but the library as well - it should be in the normal python installation under PYTHON/libs.

                C Offline
                C Offline
                ChrisW
                wrote on last edited by
                #7

                @jsulm
                Thanks mod!

                1 Reply Last reply
                1

                • Login

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