C++ (Qt)// cppcontext->registerClass(&vec::staticMetaObject, "", PythonQtCreateObject<vec>); // pythonpt = vec()
C++ (Qt)// cppcontext->registerClass(&vec::staticMetaObject, "example", PythonQtCreateObject<vec>); // pythonimport from PythonQt.example vecpt = vec()
// cppcontext->registerClass(&vec::staticMetaObject, "example", PythonQtCreateObject<vec>);...context.evalScript("from PythonQt.example import *");
pt = vec()
>del pt
C++ (Qt)throw std::runtime_error("Stop!");
C++ (Qt)bool CPyBase::AdjustDict( void ){ PyObject * object = PythonQt::self()->getMainModule(); PyObject * dict = PyModule_GetDict(object); if (!dict) return false; if (!PyDict_Check(dict)) return false; PyObject * keys = PyDict_Keys(dict); if (!keys) return false; bool doSave = mVarNames.size() == 0; QStringList doomed; int count = PyList_Size(keys); for (int i = 0; i < count; ++i) { PyObject * key = PyList_GetItem(keys, i); QString name = PyString_AsString(key); Py_DECREF(key); if (doSave) mVarNames.insert(name); else if (!mVarNames.contains(name) && !mCustomGlobals.contains(name)) doomed.push_back(name); } for (int i = 0; i < doomed.size(); ++i) PythonQt::self()->removeVariable(object, doomed[i]); return true;}