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. Trying to call python functions from my GUI, compiler is out of heap space
Forum Updated to NodeBB v4.3 + New Features

Trying to call python functions from my GUI, compiler is out of heap space

Scheduled Pinned Locked Moved Unsolved General and Desktop
17 Posts 4 Posters 1.2k Views 3 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #2

    Hi,

    Why are you including both since you want to use pybind11 ?

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

    L 1 Reply Last reply
    0
    • SGaistS SGaist

      Hi,

      Why are you including both since you want to use pybind11 ?

      L Offline
      L Offline
      lfreeman6490
      wrote on last edited by lfreeman6490
      #3

      @SGaist I was told I needed both. Getting rid of the 'python.h' import and leaving in the 'pybind11' import does not get rid of the error. Getting rid of pybind11 but leaving in python.h does get rid of the error

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

        Which compiler are you using ?
        On which platform ?

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

        L 1 Reply Last reply
        1
        • SGaistS SGaist

          Which compiler are you using ?
          On which platform ?

          L Offline
          L Offline
          lfreeman6490
          wrote on last edited by
          #5

          @SGaist I'm using QTCreator v3.0.1
          c++ GUI
          windows 10
          32bit python 2.7

          mrjjM 1 Reply Last reply
          0
          • L lfreeman6490

            @SGaist I'm using QTCreator v3.0.1
            c++ GUI
            windows 10
            32bit python 2.7

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #6

            @lfreeman6490

            Hi and which compiler mingw or visual studio ?

            L 1 Reply Last reply
            0
            • mrjjM mrjj

              @lfreeman6490

              Hi and which compiler mingw or visual studio ?

              L Offline
              L Offline
              lfreeman6490
              wrote on last edited by
              #7

              @mrjj mingw

              mrjjM 1 Reply Last reply
              0
              • L lfreeman6490

                @mrjj mingw

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #8

                @lfreeman6490
                Hi
                Im not sure if that is supported.
                https://github.com/pybind/pybind11

                Its not listed in compilers.

                Also is this 32 bit mingw ?
                or 64 ?

                L 1 Reply Last reply
                0
                • mrjjM mrjj

                  @lfreeman6490
                  Hi
                  Im not sure if that is supported.
                  https://github.com/pybind/pybind11

                  Its not listed in compilers.

                  Also is this 32 bit mingw ?
                  or 64 ?

                  L Offline
                  L Offline
                  lfreeman6490
                  wrote on last edited by
                  #9

                  @mrjj It's 32 bit, I used pip to install it. If it is not supported are you aware of another way that I can call python functions?

                  mrjjM 1 Reply Last reply
                  0
                  • L lfreeman6490

                    @mrjj It's 32 bit, I used pip to install it. If it is not supported are you aware of another way that I can call python functions?

                    mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #10

                    @lfreeman6490

                    From link
                    3, Microsoft Visual Studio 2015 Update 3 or newer

                    It does support visual studio 2015 it seems so that might work with 32 bit.

                    So you could install vs 2015 compiler if that can work with your app ?

                    L 1 Reply Last reply
                    0
                    • mrjjM mrjj

                      @lfreeman6490

                      From link
                      3, Microsoft Visual Studio 2015 Update 3 or newer

                      It does support visual studio 2015 it seems so that might work with 32 bit.

                      So you could install vs 2015 compiler if that can work with your app ?

                      L Offline
                      L Offline
                      lfreeman6490
                      wrote on last edited by lfreeman6490
                      #11

                      @mrjj I've been headed this direction and I ditched pybind11, I have been able to get my python file to compile, but not much after that. My file is "test_py_file" and my function is "test_function". There are no errors being thrown at the moment, but also it is not executing the function.

                      void f_pathloss::on_pb_tester_connect_disconnect_clicked()
                      {
                      
                          PyObject *pName, *pModule, *pDict, *pFunc, *pValue, *presult;
                      
                          Py_Initialize();
                          pName = PyString_FromString((char*)"test_py_file");
                          pModule = PyImport_Import(pName);
                          pDict = PyModule_GetDict(pModule);
                      
                          pFunc = PyDict_GetItemString(pDict, (char*)"test_function");
                      
                      
                          Py_Finalize();
                      }
                      
                      JonBJ 1 Reply Last reply
                      0
                      • L lfreeman6490

                        @mrjj I've been headed this direction and I ditched pybind11, I have been able to get my python file to compile, but not much after that. My file is "test_py_file" and my function is "test_function". There are no errors being thrown at the moment, but also it is not executing the function.

                        void f_pathloss::on_pb_tester_connect_disconnect_clicked()
                        {
                        
                            PyObject *pName, *pModule, *pDict, *pFunc, *pValue, *presult;
                        
                            Py_Initialize();
                            pName = PyString_FromString((char*)"test_py_file");
                            pModule = PyImport_Import(pName);
                            pDict = PyModule_GetDict(pModule);
                        
                            pFunc = PyDict_GetItemString(pDict, (char*)"test_function");
                        
                        
                            Py_Finalize();
                        }
                        
                        JonBJ Offline
                        JonBJ Offline
                        JonB
                        wrote on last edited by JonB
                        #12

                        @lfreeman6490
                        You pasted this code elsewhere with the same comment. How do you/we know it is doing nothing? And I asked you whether you really have test_py_file and test_function in it, else what do you expect?

                        And I also suggested you try a different example @mrjj had quoted you.

                        It helps if we keep the same question in one thread....

                        1 Reply Last reply
                        2
                        • mrjjM Offline
                          mrjjM Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on last edited by mrjj
                          #13

                          Hi
                          There is something missing

                          pFunc = PyDict_GetItemString(pDict, (char*)"test_function");

                          this gets you a function pointer but you do not call it.

                          something like
                          PyObject* myResult = PyObject_CallObject(pFunc , args)

                          args can be NULL if none is needed

                          L 1 Reply Last reply
                          1
                          • mrjjM mrjj

                            Hi
                            There is something missing

                            pFunc = PyDict_GetItemString(pDict, (char*)"test_function");

                            this gets you a function pointer but you do not call it.

                            something like
                            PyObject* myResult = PyObject_CallObject(pFunc , args)

                            args can be NULL if none is needed

                            L Offline
                            L Offline
                            lfreeman6490
                            wrote on last edited by
                            #14

                            @mrjj I decided to use pybind11, I'm still fighting off errors this way but it seems better. Thank you for the suggestions

                            mrjjM 1 Reply Last reply
                            0
                            • L lfreeman6490

                              @mrjj I decided to use pybind11, I'm still fighting off errors this way but it seems better. Thank you for the suggestions

                              mrjjM Offline
                              mrjjM Offline
                              mrjj
                              Lifetime Qt Champion
                              wrote on last edited by
                              #15

                              Hi
                              Well pybind11 is harder to get going but will be much nicer code-wise than the PyObject_xxxx interface for a more
                              complete integration but If you only need to call one function in python, pyBind11 might be a little overkill but
                              is then very future proof.

                              L 1 Reply Last reply
                              0
                              • mrjjM mrjj

                                Hi
                                Well pybind11 is harder to get going but will be much nicer code-wise than the PyObject_xxxx interface for a more
                                complete integration but If you only need to call one function in python, pyBind11 might be a little overkill but
                                is then very future proof.

                                L Offline
                                L Offline
                                lfreeman6490
                                wrote on last edited by
                                #16

                                @mrjj yeah I've been struggling with pybind11 a ton so far. Haven't gotten much of anywhere really. But I am going to need to use a decent amount of functions from the Python file

                                mrjjM 1 Reply Last reply
                                0
                                • L lfreeman6490

                                  @mrjj yeah I've been struggling with pybind11 a ton so far. Haven't gotten much of anywhere really. But I am going to need to use a decent amount of functions from the Python file

                                  mrjjM Offline
                                  mrjjM Offline
                                  mrjj
                                  Lifetime Qt Champion
                                  wrote on last edited by
                                  #17

                                  @lfreeman6490

                                  Hi
                                  What kind of errors ?

                                  make sure to read the docs as its a bit hysteric with the compilers
                                  https://pybind11.readthedocs.io/en/stable/basics.html

                                  The PyObject_CallObject API didnt work for you or why did you give it up so fast ?

                                  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