为 Python 逻辑创建 C++ Qt Gui [英] Creating a C++ Qt Gui for a Python logic

查看:26
本文介绍了为 Python 逻辑创建 C++ Qt Gui的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到了一个 Python 逻辑,我需要为其创建一个 GUI.我想为此目的使用 Qt,理想情况下,我想用 C++ 对其进行编程,而不使用 Qt Creator.

I was presented with a Python logic for which I need to create a GUI. I want to use Qt for that purpose and ideally I would like to program it in C++, without using the Qt Creator.

将 C++ Qt GUI 和 Python 逻辑结合起来的推荐方法是什么,也许带有 Python 或 C++ 中的控制层?

What are recommended ways of combining a C++ Qt GUI and a Python logic, perhaps with a controlling layer which is either in Python or C++?

由于之前的研究,我知道某些工具,如 PySide、PythonQt、SWIG、Shiboken 等(虽然我目前还没有使用它们)并且将 *.ui 文件导入 Python 非常简单,但是可能的方法数量有点多,到目前为止我还没有想出一个好的解决方案".

Due to prior research, I'm aware of certain tools like PySide, PythonQt, SWIG, Shiboken and others (although I haven't used them so far) and that it is very simple to import *.ui files into Python, but the number of possible ways is a bit overwhelming and I could not come up with a "good solution" so far.

理想情况下,我不会使用 Qt 设计器,而是手动创建 GUI(窗口、自定义小部件、帮助程序类等),将它们组合成一个或几个类,我公开给 Python/C++ 控制层(通过包装器?DLL?)管理 GUI 和逻辑之间的通信.

Ideally, I would not use Qt Designer, but create the GUI (windows, custom widgets, helper classes etc) by hand, combine them into one or few classes which I expose to a Python/C++ controlling layer (by wrappers? DLL?) which manages the communication between GUI and logic.

我怎样才能做到这一点?

How can I achieve this?

这个问题的简短版本可能只是:如何将 Qt C++ GUI 与 Python 逻辑结合使用?

A short version of this question might just be: How can I use a Qt C++ GUI with a Python logic?

推荐答案

您可以使用 qt c++ 创建您的 GUI 应用程序,并包装在嵌入 python api 的 python api 中编写的控制器逻辑.https://docs.python.org/2/extending/embedding.html但是如果你有很多方法会很无聊,而且如果在 C++ 端写得不好,你可能会出现一些内存泄漏.

You can create your GUI application using qt c++ and wrap controler logic written in a python api embedding the python api. https://docs.python.org/2/extending/embedding.html But if you have many methods that will be boring to do and you may have some memory leaks if not well written in th c++ side.

另一种解决方案可能是使用 web 服务(rest api/json rpc ....Etc ...)对 python api 使用 rpc 调用.Qt 应用程序是 python rest api 的客户端.像这样,您将 c 代码与 python 代码分开.您可以使用 json rpc 调用或其他 api,例如 jcon (https://github.com/joncol/jcon-cpp).你也可以找到python和QT xml rpc api能够一起交谈.

Another solution may be using rpc calls to a python api using a webservice (rest api/json rpc ....Etc...). Qt application is client of a python rest api. like this you split the c code from the python one. You can do that using json rpc calls , or other apis,like jcon (https://github.com/joncol/jcon-cpp). You will too be able to find python and QT xml rpc api able to talk together.

swig (http://swig.org) 可能有一些能力,但最好用在其他方式:从python调用c func

swig (http://swig.org) may have some capability , but it is better used in the other way : calling c func from python

这篇关于为 Python 逻辑创建 C++ Qt Gui的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆