mody python modul to excues python script

This commit is contained in:
jiegeaiai 2024-12-13 00:58:17 +08:00
parent 68711e53c4
commit 6ebddb2022

View File

@ -17,7 +17,7 @@ PythonModule::PythonModule(QObject* parent)
assert(init_); assert(init_);
QString appDir = QString("%1/test.py").arg(Application::applicationDirPath()); QString appDir = QString("%1/test.py").arg(Application::applicationDirPath());
CallFunction(appDir, "test"); CallFunction("myPyTest", "myFunc");
} }
PythonModule::~PythonModule() { PythonModule::~PythonModule() {
@ -47,10 +47,19 @@ bool PythonModule::CallFunction(const QString& py, const QString& name) {
} }
PyObject* func = PyObject_GetAttrString(module, name.toStdString().c_str()); PyObject* func = PyObject_GetAttrString(module, name.toStdString().c_str());
if (nullptr == func) { if (nullptr == func) {
PyErr_Print();
LOG_WARN("PyObject_GetAttrString faile: {}", name.toStdString()); LOG_WARN("PyObject_GetAttrString faile: {}", name.toStdString());
return false; return false;
} }
PyObject_CallFunction(func, NULL);
//PyObject* arg = Py_BuildValue("i", 32);
PyObject* ret = PyObject_CallFunction(func, "i", 32);
if (nullptr != ret) {
int value = 0;
int r = PyArg_Parse(ret, "i", &value);
LOG_INFO("PyArg_Parse : r:{}, value:{}", r, value);
}
return true; return true;
} }