As the first task, we will implement the last program using an object-oriented API. Create a new console project and add the following class to it:
class QtPython : public QObject { Q_OBJECT public: QtPython(QObject *parent = 0); ~QtPython(); void run(const QString &program); private: QVector<wchar_t> programNameBuffer; };
The implementation file should look like this:
#include <Python.h> //... QtPython::QtPython(QObject *parent) : QObject(parent) { QStringList args = qApp->arguments(); if (args.count() > 0) { programNameBuffer.resize(args[0].count()); args[0].toWCharArray(programNameBuffer.data()); Py_SetProgramName(programNameBuffer.data()); } Py_InitializeEx(0); } QtPython::~QtPython() ...