Qt中使用python--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
        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();

}


阅读更多 登录后自动展开
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页