1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| #include <QCoreApplication> #include <iostream> #include <Python.h> #include <QDebug> using namespace std;
int main(int argc, char *argv[]) { QCoreApplication a(argc, argv);
Py_Initialize();
if (!Py_IsInitialized()) { return -1; }
PyObject* pModule = PyImport_ImportModule("wtnn"); if (!pModule) { printf("Can't open python file!\n"); return -1; }
PyObject* pFun = PyObject_GetAttrString(pModule, "judge");
if (!pFun) { printf("Get function failed"); return -1; }
PyObject* args = Py_BuildValue("(s)", "测试"); PyObject* result = PyObject_CallObject(pFun, args); if (result) { char* str = nullptr; PyArg_Parse(result, "s", &str); qDebug() << str; }
Py_Finalize();
return a.exec(); }
|