如何解决Qt中使用python与解决错误并输出Hello Python

本文档详细介绍了如何在Qt应用中集成Python,包括在Windows和Linux环境下配置Python的include和lib路径,以及解决在编译过程中遇到的cmath错误。通过这些步骤,你将能够成功运行包含Python代码的Qt应用,并打印出'Hello Python!'。

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!
 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值