January 2016
Beginner
512 pages
12h 35m
English
Create a new class and call it QtPythonValue. Then, add the following code to it:
#include <Python.h> class QtPythonValue { public: QtPythonValue() { incRef(Py_None);} QtPythonValue(const QtPythonValue &other) { incRef(other.m_value); } QtPythonValue& operator=(const QtPythonValue &other) { if(m_value == other.m_value) return *this; decRef(); incRef(other.m_value); return *this; } QtPythonValue(int val) { m_value = PyLong_FromLong(val); } QtPythonValue(const QString &str) { m_value = PyUnicode_FromString(qPrintable(str)); } ~QtPythonValue() { decRef(); } int toInt() const { return PyLong_Check(m_value) ? PyLong_AsLong(m_value) : 0; } QString toString() const { return PyUnicode_Check(m_value) ...