1. 程式人生 > >Qt中使用python--Hello Python!

Qt中使用python--Hello Python!

pre final pri 圖片 linux 工程 pla color nali

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
        3.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();
          }   

技術分享圖片技術分享圖片技術分享圖片


Qt中使用python--Hello Python!