如何通过Python C api在QT和Python之间进行接口

How to interface between QT with Python by Python C api

本文关键字:Python 之间 接口 何通过 api QT      更新时间:2023-10-16

我正在编写一个与python接口的Qt程序。我必须将Circle类的C++对象直接发送到Python

    1) Need to create a Python Module ( let say Shape )
    2) Need to add a Python Class PCircle in Shape module which is equivalent to C++ 
       Circle class.
    3) Do the calculation on Python Environment ( Python 3.4)
    4) Populate the data into PCircle Object in Python
    5) Send it back to Qt Environment by storing the PCircle values to C++ Circle Object    
    and show the changes in real time in display

这就是我如何描述我的问题以及我的目标,如果有什么不清楚的地方,请评论。

感谢

  1. 模块只是一个python文件。。。所以只需创建一个名为Shape.py的文件
  2. 打开Shape.py并添加

代码

from PyQt4 import QWidget
class PCircle(QWidget):
    #implement methods here that are available to the QTCircleWidget
  1. 在python中进行某种计算

代码

def calculation(something):
    return somthing**2
  1. 只需添加代码my_circle = PCircle(x,y,radius)
  2. 打印出要返回给调用程序的任何数据。调用程序将需要解析该数据并对其进行处理