python封装类,debug版本不清理,否则崩溃

This commit is contained in:
DESKTOP-450PEFP\mainc 2026-04-10 10:25:34 +08:00
parent 5d054c35db
commit 058bd7e337

View File

@ -199,7 +199,10 @@ QVariant PythonHandler::pythonObjectToQVariant(PyObject *obj)
map[key] = pythonObjectToQVariant(pValue);
}
}
#ifdef _RELEASE
Py_DECREF(pKeys);
#endif
return map;
}
else if (obj == Py_None) {
@ -222,14 +225,17 @@ QString PythonHandler::capturePythonError() {
PyObject* pstr = PyObject_Str(pvalue);
if (pstr) {
errorMsg = QString::fromUtf8(PyUnicode_AsUTF8(pstr));
#ifdef _RELEASE
Py_DECREF(pstr);
#endif
}
}
#ifdef _RELEASE
// 清理
Py_XDECREF(ptype);
Py_XDECREF(pvalue);
Py_XDECREF(ptraceback);
#endif
return errorMsg;
}
@ -284,8 +290,11 @@ QVariant PythonHandler::executeScript(const QString &scriptPath,
PyErr_Print();
}
emit addLog("无法找到函数:" + functionName);
#ifdef _RELEASE
Py_XDECREF(pFunc);
Py_DECREF(pModule);
#endif
return QVariant();
}
@ -427,7 +436,10 @@ QVariant PythonHandler::executeCode(const QString &code)
if (pResult) {
QVariant result = pythonObjectToQVariant(pResult);
#ifdef _RELEASE
Py_DECREF(pResult);
#endif
return result;
} else {
PyErr_Print();