在pro配置文件中,添加庫和包含路徑。
LIBS += -L D:/Anaconda/libs -lpython37
INCLUDEPATH += D:/Anaconda/include
#include<iostream>
Py_SetPythonHome(L"D:/Anaconda");
Py_Initialize();
if ( !Py_IsInitialized() )
qDebug()<<"false py\n";
else
qDebug()<<"true py";
pModule = PyImport_ImportModule("ANN");
if (!pModule)
qDebug()<<"Cant open python file!\n";
else
qDebug()<<"open python file ok!";
pyPredict = PyObject_GetAttrString(pModule,"Pr");
Qt調用Python模塊分爲設置路徑、初始化、導入py文件(模塊)、調用模塊中函數。