January 2016
Beginner
512 pages
12h 35m
English
The next task is to provide ways to invoke Python functions and return values from scripts. Let's start by providing a richer run() API. Implement the following method in the QtPython class:
QtPythonValue QtPython::run(const QString &program, const QtPythonValue &globals, const QtPythonValue &locals)
{
PyObject *retVal = PyRun_String(qPrintable(program),
Py_file_input, globals.m_value, locals.m_value);
return QtPythonValue(retVal);
}We'll also need a functionality to import Python modules. Add the following methods to the class:
QtPythonValue QtPython::import(const QString &name) const { return QtPythonValue(PyImport_ImportModule(qPrintable(name))); } QtPythonValue QtPython::addModule(const ...