step1:install Python (version 2.7 or higher);
step2:The configuration is as follows:
1.create qt console application
2.windows:在.pro工程文件里添加python版本的include和lib路径:
INCLUDEPATH +=C:/Python27/include
LIBS +=C:/Python27/libs/python27.lib
linux:在.pro工程文件里添加python版本的include和lib路径:
INCLUDEPATH += –I C:\Python27\include
LIBS += –L C:\Python27\libs –lpython27
step3.main.cpp
#include <QCoreApplication>
#include <Python.h>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
Py_SetProgramName(argv[0]);
Py_Initialize();
PyRun_SimpleString("print 'Hello Python!'\n");
Py_Finalize();
return a.exec();
}
step4:会遇到的问题是:
cmath:1136: error: '::hypot' has not been declared
using ::hypot;
此时需要在#include<python.h>前面加上#include<math.h>.至此问题解决,成功输出hello--python!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)