There is an application written from scratch in c ++ and Qt 5. We need to add Python scripting in the style of 3ds max, that is, like this:

  1. We type the script in the editor built into the application.
  2. Save it.
  3. Press the Evaluate button and execute the script.

Perform in such a way as to have access from one script to the entire object model of the application. I found the lessons, but the situation is deplorable: extension is required - so that the application was originally written in Python. Otherwise, the advice is one: the method on c ++ is taken and the same method on Python is called with the required number of arguments, and I have nothing in Python except the arguments. How to get access to the entire application object model from embedded Python?

1 answer 1

Python is embedded in the application like this:

 #include <Python.h> int main(int argc, char *argv[]) { Py_SetProgramName(argv[0]); /* optional but recommended */ Py_Initialize(); PyRun_SimpleString("from time import time,ctime\n" "print 'Today is',ctime(time())\n"); Py_Finalize(); return 0; } 

More in official documentation https://docs.python.org/2/extending/embedding.html

  • Does this give access to the objects positive? - Vladimir Gamalyan
  • I know it. I already built in. I rested in the question that ends my post ... - Ilia Ivanov
  • @VladimirGamalian write - give. If the author of Qt - through MOC, you can get a lot of things. - Vladimir Martyanov
  • @IliaIvanov will not automatically do anything, it’s not realistic to recognize a bunch of classes in automatic mode. Use MOC, it is quite possible to manipulate Qt objects. But this is a completely different question, having no relation to the python ... - Vladimir Martyanov
  • 3
    @IliaIvanov You will not believe, but about "Extending Embedded Python" is under the link given by me. - Vladimir Martyanov