java - Qt 的语言绑定(bind)是否以特定语言重新实现 Qt 模块?

标签 java c++ qt pyqt qt-jambi

我想知道 Qt 的语言绑定(bind)(如 Qt Jambi 和 PyQt)是否实现了所有 Qt 模块。也就是说,无论它们只是将目标语言(JAVA、python 等)与 Qt C++ 模块相结合的一种方式,还是目标语言与使用目标语言实现的模块一起工作。

例如一个简单的问题是:Qt Jambi 是否与用 Java 编写的 Qt 模块一起工作? (如果是,我们可以编写能够在不同平台上运行的 Qt Jambi 应用程序吗?即所有 Qt Jambi 模块都是一些 jar 文件吗?)

最佳答案

就 PyQt 而言,它是否“实现了所有 Qt 模块”的答案是:是和否。但大多数情况下没有。

PyQt 使用 SIP生成其绑定(bind)的工具。如果您想了解这是如何完成的,这里是 PyQt 和 SIP 的作者如何解释这个过程:

For PyQt v4 I use an internal tool (written using PyQt of course) called metasip. This is sort of an IDE for SIP. It uses GCC-XML to parse the latest header files and saves the relevant data, as XML, in a metasip project. metasip then does the equivalent of a diff against the previous version of the API and flags up any changes that need to be looked at. Those changes are then made through the GUI and ticked off the TODO list. Generating the .sip files is just a button click. In my subversion repository, PyQt v4 is basically just a 20M XML file. Updating PyQt v4 for a minor release of Qt v4 is about half an hours work.

In terms of how the generated code works then I don't think it's very different from how any other bindings generator works. Python has a very good C API for writing extension modules - it's one of the reasons why so many 3rd party tools have Python bindings. For every C++ class, the SIP generated code creates a corresponding Python class implemented in C.

所以 PyQt 只是一组围绕 Qt 模块的相当薄的包装器,通常本身不实现任何功能。但是,也有一些异常(exception)。

首先,PyQt 在各个地方添加了一些语法糖以使 Qt API 更适合 Python 编码人员(例如,new-style signal and slot support)。

其次,由于 C++ 和 Python 之间的基本语言差异(例如,没有什么等同于 Python 中的类型转换),PyQt 无法提供一些 Qt API。

最后,还有 uic module .与 PySide 不同,PyQt 不包装 QtUiTools模块。相反,它提供了一个用纯 Python 编写的模块,该模块实际上确实实现了 Qt 库中的等效功能。但这是异常(exception),而不是规则。

除了上述之外,毫无疑问还有许多其他差异和遗漏,我没有在此处介绍(特别是关于 PyQt5)。与所有语言绑定(bind)一样,基本目标是提供一种实用两种语言之间的通信方式,而不是完美的一对一映射。

关于java - Qt 的语言绑定(bind)是否以特定语言重新实现 Qt 模块?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22433135/

相关文章:

java - Servlet 过滤器和线程?

Java NIO Files.createFile() 失败并出现 NoSuchFileException

c++ - char* 类型的值不能用于初始化 “char” 类型的实体

c++ - Ghostscript api 请求 "press <return> to continue"

python - PyQt:激活 QListWidget 项目

c++ - 如何去掉标题栏左侧的默认菜单——Qt?

java - 我在 Android 代码中做错了什么?

java - 斐波那契数列 long[] 数组在索引 92 后抛出负数

java - GetStringUTFChars 及其字符串复制行为

c++ - 我可以将一个内存池用于多个 vector 吗?