在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文件(模块)、调用模块中函数。
本文详细介绍如何在Qt中配置并调用Python模块,包括设置库路径、初始化Python环境、导入Python文件及调用模块函数的步骤。通过具体代码示例,展示了跨语言调用的实现过程。
8037

被折叠的 条评论
为什么被折叠?



