QT 调用 python 出现问题,帮忙看下是因为什么问题,万分感谢!

疏星暗淡 2018-06-27 06:05:19
报错信息如下

pro文件


文件代码


#include <QCoreApplication>
#include <Python.h>
#include <pythonrun.h>
#include <iostream>
using namespace std;


int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);

//PyRun_SimpleString("import sys");
char uc[20] = "C:\\Python27";
Py_SetPythonHome(uc);
//初始化python模块
Py_Initialize();
if ( !Py_IsInitialized() )
{
return -1;
}
//导入test.py模块
PyObject* pModule = PyImport_ImportModule("test");
if (!pModule) {
printf("Cant open python file!\n");
return -1;
}
//获取test模块中的hello函数
PyObject* pFunhello= PyObject_GetAttrString(pModule,"hello");

if(!pFunhello){
cout<<"Get function hello failed"<<endl;
return -1;
}
//调用hello函数
PyObject_CallFunction(pFunhello,NULL);
//结束,释放python
Py_Finalize();

return a.exec();
}

...全文
166 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
疏星暗淡 2018-06-28
  • 打赏
  • 举报
回复
找到原因了 Python64bit QT32bit不对应,换了对应的版本就ok了。

24,854

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧