29

Qt混合Python开发技术:Python介绍、混合过程和Demo

 3 years ago
source link: http://www.cnblogs.com/qq21497936/p/13942711.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Qt中混合Python开发,可调用Python命令与脚本。

Python是一种跨平台的计算机程序设计语言。 是一个高层次的结合了解释性、编译性、互动性和面向对象的脚本语言。最初被设计用于编写自动化脚本(shell),随着版本的不断更新和语言新功能的添加,越多被用于独立的、大型项目的开发。

Python是一种解释型脚本语言,可以应用于以下领域:

  • Web 和 Internet开发
  • 科学计算和统计
  • 人工智能
  • 桌面界面开发
  • 软件开发
  • 后端开发
  • 网络爬虫

下载Python

3.x版本的对一些函数做了限制,2.x支持,所以使用2.x,选了一个python自带pip的,版本为Python2.7.13。

官网下载地址:https://www.python.org/downloads/

下载后,安装即可。

笔者补充

Python学习笔记后续会陆续发布,只讲实用不废话,最快速度上手Python。

Qt引入Python库

按照模块化,将python的libs和include目录拷贝到模块的路径下(参照“模块化”),模块pri文件如下:

2UnIVf6.png!mobile
INCLUDEPATH += $$PWD
DEPENDPATH += $$PWD

HEADERS += \
    $$PWD/PythonManager.h

SOURCES += \
    $$PWD/PythonManager.cpp

# python2.7.13
INCLUDEPATH += \
    $$PWD/python2.7.13/include
LIBS += -L$$PWD/python2.7.13/libs
LIBS += -lpython27

3A3eyiR.png!mobile

测试运行

引入模块后的工程部署:

mIzq6rj.png!mobile

测试代码:

2iymu2Q.png!mobile

测试的python脚本和输出结果:

UBb22a.png!mobile

工程模版v1.0.0

N7BVJbN.png!mobile


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK