深度解析 Qt 与 Python 混合架构:嵌入、交互与工程化实践
深度解析 Qt 与 Python 混合架构:嵌入、交互与工程化实践
1. 混合编程架构综述:Qt 与 Python 的协同演进
在当代软件工程的图谱中,C++ 与 Python 分别占据了高性能系统编程与快速应用开发的极点。Qt 框架作为 C++ 领域中构建跨平台图形用户界面(GUI)的事实标准,以其卓越的渲染性能、元对象系统(Meta-Object System)和信号槽机制(Signals & Slots)著称。然而,C++ 的静态编译特性在面对需要高度动态性、插件扩展能力或利用数据科学生态(如 AI/ML 模型推理)的场景时,往往显得开发效率不足或灵活性受限。
Python 的引入填补了这一空白。将 Python 解释器嵌入 Qt 应用程序,不仅能够保留 C++ 在核心业务逻辑和界面渲染上的性能优势,还能赋予应用脚本化的动态能力。这种“C++ 构建骨架,Python 填充血肉”的混合架构模式,已广泛应用于视觉特效软件(VFX)、科学仪器控制界面、电子设计自动化(EDA)工具以及量化交易终端等领域。
本报告将对 Qt 调用 Python 的技术实现进行详尽的实证研究,涵盖从底层的解释器嵌入机制到上层的复杂数据类型转换、并发控制以及工程化部署的全链路。分析将基于原生 Python/C API、pybind11、PythonQt 及 Shiboken 等主流方案的对比,揭示其在架构设计中的权衡与最佳实践。
2. 集成技术栈的深度对比与选型策略
在启动混合开发之前,架构师面临的首要决策是选择何种“胶水”技术来连接 C++ 与 Python。这并非简单的二元选择,而是需要在开发效率、运行时性能、编译复杂度以及对 Qt 特性的原生支持度之间进行多维度的权衡。
2.1 原生 Python/C API:底层的双刃剑
Python/C API 是 CPython 解释器暴露给 C 语言的一组函数接口,它是所有高级绑定库的基础。使用原生 API 的最大优势在于其零依赖性——除了 Python 开发头文件和动态库外,无需引入任何第三方库。这使得它在对二进制体积极度敏感或对构建链有严格限制的嵌入式环境中具有不可替代的地位。
然而,原生 API 的使用成本极高。它要求开发者手动管理 PyObject* 的引用计数(Reference Counting)。在复杂的逻辑分支中,遗漏一次 Py_DECREF 调用就会导致内存泄漏,而多调用一次则会引发段错误(Segmentation Fault)。此外,原生 API 不支持 C++ 的面向对象特性,将 C++ 类映射到 Python 需要编写大量的样板代码(Boilerplate Code),定义类型结构体(PyTypeObject)、方法表(PyMethodDef)以及复杂的 getter/setter。
数据交互方面,原生 API 处理 Qt 类型(如 QString、QVector)需要繁琐的手动转换。例如,将 QString 转换为 Python 字符串需要先转为 std::string 或 UTF-8 字符数组,再调用 PyUnicode_FromString,整个过程缺乏类型安全保障。
2.2 pybind11:现代 C++ 的优雅桥梁
pybind11 是当前 C++ 社区集成 Python 的首选方案,被广泛视为 Boost.Python 的轻量级、现代化替代品。作为一个 Header-only 的库,它极易集成到现有的构建系统中,仅需包含头文件即可使用,无需预编译库文件。
核心优势分析:
- RAII 与生命周期管理:pybind11 利用 C++11 的 RAII(资源获取即初始化)特性,自动处理 Python 对象的引用计数。例如,py::scoped_interpreter 类可以确保解释器在对象销毁时自动关闭,极大地降低了资源管理的复杂度。
- 类型推导与自动转换:它通过模板元编程技术,能够自动推导 C++ 函数的参数和返回值类型,并将其映射到对应的 Python 类型。对于 STL 容器(如 std::vector、std::map),pybind11 提供了开箱即用的自动转换支持。
- 零开销抽象:尽管提供了高级抽象,pybind11 在编译时会优化掉大部分模板代码,生成的二进制文件体积小且运行时开销极低,非常适合对性能有要求的场景。
尽管 pybind11 原生不直接支持 Qt 类型(如 QString),但其强大的自定义类型转换器(Type Caster)机制允许开发者编写简短的模板特化代码,从而实现 Qt 类型与 Python 类型的无缝互操作。
2.3 PythonQt:Qt 元对象系统的深度结合
与 pybind11 侧重于通用 C++ 绑定不同,PythonQt 是专为 Qt 设计的。它利用 Qt 强大的元对象系统(Meta-Object System)和运行时反射机制,能够动态地将继承自 QObject 的类暴露给 Python,而无需为每个类编写绑定代码。
PythonQt 的主要优势在于其对 Qt 信号槽机制的原生支持。开发者可以在 Python 脚本中直接连接 C++ 发出的信号,或者调用 C++ 对象的槽函数。这使得它非常适合用于构建需要让用户通过脚本完全控制 GUI 行为的应用程序(如自动化测试工具或高度可配置的 IDE)。然而,由于过度依赖运行时反射,PythonQt 在调用性能上通常不如编译时绑定的 pybind11,且其社区活跃度相对较低。
2.4 Shiboken (Qt for Python):官方的重量级方案
Shiboken 是 Qt 官方项目 Qt for Python (PySide) 背后的绑定生成器。虽然它主要用于将 C++ 库生成为 Python 扩展模块(Extension Module),但也支持将 Python 嵌入到 C++ 应用中。
Shiboken 的最大优势在于它能生成最“地道”的 Qt 绑定,与 PySide 生态完美兼容。如果项目已经大量使用了 PySide,或者需要将复杂的 C++ Qt 库完整地暴露给 Python,Shiboken 是最佳选择。但是,Shiboken 的构建过程复杂,需要解析 C++ 头文件并生成中间代码,对构建环境的依赖较重(需要 Clang),这增加了工程的维护成本。
2.5 技术选型总结表
| 维度 | 原生 Python/C API | pybind11 | PythonQt | Shiboken (PySide) |
|---|---|---|---|---|
| 集成难度 | 极高 (样板代码多) | 低 (Header-only) | 中 (需编译库) | 高 (生成器流程复杂) |
| Qt 亲和度 | 低 (需手动转换) | 中 (需自定义 Caster) | 极高 (基于元对象) | 高 (官方支持) |
| 性能表现 | 最高 (无中间层) | 极高 (编译优化) | 中 (运行时反射) | 高 |
| 内存安全 | 风险极高 (手动计数) | 安全 (RAII 管理) | 安全 (Qt 父子机制) | 安全 |
| 推荐场景 | 极简嵌入、无依赖环境 | 通用嵌入、高性能计算 | 脚本化 UI 控制 | 大型 Qt 库绑定 |
综合考量,对于大多数需要在 Qt 应用中嵌入 Python 以执行逻辑计算、数据处理或简单脚本任务的现代 C++ 项目,pybind11 凭借其现代化的设计、易用性和性能平衡,成为当前的最佳实践标准。因此,本报告后续的实现细节将重点围绕 pybind11 展开。
3. 构建系统的集成与环境配置
在确定技术路线后,构建系统的配置是工程化的第一步。由于涉及 C++ 编译器、Qt MOC (Meta-Object Compiler)、Python 解释器库以及 pybind11 模板库的混合编译,构建配置的正确性直接决定了项目的跨平台可移植性。
3.1 依赖环境的准备
开发环境必须严格匹配版本依赖,以避免二进制兼容性问题(ABI Compatibility Issues):
- Qt SDK:建议使用 Qt 5.15 LTS 或 Qt 6.x 版本。
- Python 环境:必须安装 Python 的开发包(Development Headers/Libraries)。
- Linux (Ubuntu/Debian): 需安装 python3-dev 或 python3.x-dev。仅安装 python3 是不够的,因为它不包含 Python.h 头文件和 libpython 静态/动态库。
- Windows: 安装 Python 时必须勾选 “Download debugging symbols” 和 “Download debug binaries”。这是因为在 Visual Studio 的 Debug 模式下,链接器会寻找 python3xx_d.lib,如果缺少该文件,构建将失败。
- pybind11: 推荐作为 Git Submodule 引入项目,以锁定版本确保稳定性。
3.2 CMake 构建配置实战
CMake 是目前 C++ 生态中事实上的构建标准,pybind11 提供了完善的 CMake 支持。一个典型的 CMakeLists.txt 配置如下:
cmake_minimum_required(VERSION 3.14) project(QtPythonEmbed LANGUAGES CXX) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_AUTOMOC ON) # 开启 Qt MOC 自动处理 set(CMAKE_AUTORCC ON) set(CMAKE_AUTOUIC ON) # 1. 查找 Qt 库 find_package(Qt6 COMPONENTS Core Widgets REQUIRED) # 2. 查找 Python 组件 # Development.Embed 是 CMake 3.18+ 引入的组件,专门用于嵌入场景 # 它会自动正确配置链接标志(如 -lpython3.8 等) find_package(Python3 COMPONENTS Interpreter Development.Embed REQUIRED) # 3. 集成 pybind11 # 假设 pybind11 位于子目录中 add_subdirectory(pybind11) # 4. 定义可执行文件 add_executable(MyApp main.cpp) # 5. 链接库 # pybind11::embed 目标会自动处理 Python 库的链接和包含路径 target_link_libraries(MyApp PRIVATE Qt6::Core Qt6::Widgets pybind11::embed ) # 6. 处理 Windows 特有的导出符号问题(可选) if(MSVC) target_compile_options(MyApp PRIVATE /permissive-) endif() 深入解析:
- find_package(Python3…):这是关键步骤。在旧版 CMake 中,开发者常使用 FindPythonInterp 和 FindPythonLibs,但这容易导致解释器版本(如 Python 3.8)与库版本(如 Python 3.9)不匹配。新的 FindPython3 模块确保了版本的一致性。
- pybind11::embed:与用于编写扩展模块的 pybind11::module 目标不同,embed 目标包含了链接 libpython 所需的所有标志。在 Linux 上,它会自动处理 python3-config --libs 输出的复杂链接选项。
3.3 qmake 配置方案 (.pro)
尽管 CMake 日益流行,但在维护旧有 Qt 项目时,qmake 仍是主流。在 .pro 文件中配置 Python 嵌入较为繁琐,需要手动指定路径:
QT += core gui widgets TARGET = QtPythonEmbed TEMPLATE = app # Windows 配置示例 win32 { # 假设 Python 安装路径,实际项目中建议通过环境变量获取 PYTHON_HOME = C:/Python311 INCLUDEPATH += $$PYTHON_HOME/include # 区分 Debug 和 Release 链接不同的库 debug { LIBS += -L$$PYTHON_HOME/libs -lpython311_d } else { LIBS += -L$$PYTHON_HOME/libs -lpython311 } } # Linux 配置示例 unix:!macx { # 使用 pkg-config 获取正确的编译和链接标志 CONFIG += link_pkgconfig PKGCONFIG += python3-embed # 或者手动指定(不推荐,易受环境影响) # INCLUDEPATH += /usr/include/python3.10 # LIBS += -lpython3.10 } # 引入 pybind11 头文件 INCLUDEPATH += $$PWD/pybind11/include 在使用 qmake 时,开发者常遇到的一个陷阱是 LIBS 顺序问题。在某些 Linux 发行版上,链接器的顺序敏感,必须将 -lpython 放在依赖它的目标文件之后。
4. 嵌入式解释器的生命周期与执行模型
核心集成逻辑在于如何在 C++ 的生命周期内安全地启动、管理并关闭 Python 解释器。
4.1 解释器初始化与 RAII 模式
在原生 API 中,Py_Initialize() 和 Py_FinalizeEx() 分别用于启动和关闭解释器。然而,这种全局状态的管理容易出错。如果在 Py_Finalize() 之后尝试访问任何 Python 对象,程序将立即崩溃。
pybind11 引入了 py::scoped_interpreter 类,利用 C++ 的析构机制确保解释器生命周期的安全。
#include<pybind11/embed.h>#include<QApplication>#include<QDebug>namespace py = pybind11;intmain(int argc,char*argv){ QApplication app(argc, argv);// 关键:初始化解释器// guard 对象在 main 函数结束时销毁,自动调用 Py_Finalize py::scoped_interpreter guard{};try{ py::exec("print('Python Interpreter initialized successfully inside Qt!')");}catch(const py::error_already_set &e){qCritical()<<"Python initialization failed:"<< e.what();return-1;}return app.exec();}深度洞察:需要注意的是,CPython 的 Py_Finalize() 并不总是能释放所有内存。某些扩展模块可能会分配全局变量而不释放。此外,一旦调用 Py_Finalize(),通常不建议在同一进程中再次调用 Py_Initialize(),因为某些静态状态可能无法彻底重置。因此,在 Qt 应用中,解释器的生命周期通常应与 QApplication 的生命周期一致,即“一次初始化,直至退出”。
4.2 模块加载与脚本路径管理
嵌入式 Python 环境默认的 sys.path 可能仅包含标准库路径,而不包含应用程序的当前目录或脚本目录。为了加载自定义脚本,必须显式修改 sys.path。
voidsetupPythonPath(){ py::module_ sys = py::module_::import("sys"); py::list path = sys.attr("path");// 将当前工作目录加入 Python 搜索路径 path.append(".");// 或者添加特定的资源目录 QString scriptDir =QCoreApplication::applicationDirPath()+"/scripts"; path.append(scriptDir.toStdString());}voidexecuteScript(){try{// 导入名为 "logic" 的 logic.py 模块 py::module_ logic = py::module_::import("logic");// 调用其中的 process_data 函数 logic.attr("process_data")();}catch(py::error_already_set &e){qWarning()<<"Failed to load script:"<< e.what();}}这种机制允许开发者将业务逻辑与 C++ 编译代码解耦。通过修改 .py 文件,可以在不重新编译 Qt 应用的情况下更新程序行为,实现了类似“热更新”的效果。
5. 高级数据交互:Type Caster 与 Qt 类型映射
数据在 C++ 与 Python 之间的流转是混合编程的核心。Qt 的 QString、QVector、QMap 与 Python 的 str、list、dict 并不兼容。在原生 C-API 中,这种转换需要繁琐的手动封送(Marshaling),效率低下且容易引入内存错误。
5.1 QString 与 Python str 的无缝转换
pybind11 允许用户通过特化 type_caster 模板来扩展类型系统。这是实现 Qt 类型透明传输的关键技术。
QString Type Caster 实现原理:
- C++ 到 Python (cast):利用 QString::toUtf8() 获取 UTF-8 编码的字节流,然后调用 Python API 创建 str 对象。
- Python 到 C++ (load):检查 Python 对象是否为字符串,提取其 UTF-8 缓冲区,并使用 QString::fromUtf8() 构造对象。
// 必须放在 pybind11::detail 命名空间内namespace pybind11 {namespace detail {template<>structtype_caster<QString>{public:// 声明类型名称,用于 Python 文档生成PYBIND11_TYPE_CASTER(QString,_("str"));// Python -> C++boolload(handle src,bool){// 检查是否为 Python 字符串if(!src ||!PyUnicode_Check(src.ptr())){returnfalse;}// 获取 UTF-8 编码的数据 Py_ssize_t size;constchar*utf8 =PyUnicode_AsUTF8AndSize(src.ptr(),&size);if(!utf8){// 如果转换失败(例如编码错误),清除错误并返回 falsePyErr_Clear();returnfalse;}// 构造 QString value =QString::fromUtf8(utf8, size);returntrue;}// C++ -> Pythonstatic handle cast(const QString &src, return_value_policy /* policy */, handle /* parent */){// 将 QString 转为 UTF-8 QByteArray utf8 = src.toUtf8();// 创建 Python str 对象returnPyUnicode_FromStringAndSize(utf8.constData(), utf8.size());}};}}工程意义:一旦定义了这个转换器,所有的绑定函数都可以直接使用 QString。例如:
// C++ 函数voidupdateLabel(QString text){...}// 绑定代码 m.def("update_label",&updateLabel);// Python 调用#Python 传入 str,pybind11 自动调用 type_caster 转为 QString module.update_label("Hello from Python")这消除了代码中所有的 .toStdString() 调用,不仅代码更整洁,而且由于始终使用 UTF-8 作为中间交换格式,避免了 Windows 上常见的编码问题(如 Latin-1 vs GBK)。
5.2 容器与复杂结构的转换
对于 QVector<T> 或 QList<T>,可以采用类似的策略,将其映射为 Python 的 list。这通常涉及到遍历容器并逐个转换元素,对于大型数据集合,这可能会带来显著的性能开销(O(n) 拷贝)。
对于高性能场景(如图像处理),应避免直接转换容器,而是利用 Python 的缓冲区协议(Buffer Protocol)。C++ 可以将 QImage 的底层数据指针暴露为 Python 的 memoryview 或 NumPy 数组,从而实现零拷贝(Zero-copy)数据共享。pybind11 的 py::array_t 类型专门用于此类场景。
6. 并发控制:GIL 与 Qt 线程模型
多线程是现代 GUI 应用的标配,用于将耗时任务从主线程(UI 线程)剥离。然而,Python 的全局解释器锁(GIL)使得 C++ 多线程调用 Python 充满了死锁的风险。
6.1 GIL 的死锁机制
场景:Qt 主线程初始化了 Python(持有 GIL),然后启动一个 QThread 去执行 Python 代码。
- 主线程在 QThread::wait() 处阻塞,等待子线程结束。
- 子线程启动,尝试调用 Python 函数,需要获取 GIL。
- 死锁:主线程持有 GIL 并挂起等待子线程;子线程等待主线程释放 GIL。
此外,如果非 Python 创建的线程(如 QThread 内部生成的原生线程)直接调用 Python API 而不先注册线程状态,会导致严重的内存错误或立即崩溃。
6.2 正确的锁管理策略
为了安全地在 Qt 多线程环境中使用 Python,必须严格遵守以下协议:
步骤 1:主线程释放 GIL
在初始化 Python 后,主线程应主动释放 GIL,允许其他线程获取它。这通常通过 PyEval_SaveThread() 实现。
// 在 main.cpp 中初始化后 py::scoped_interpreter guard{};// 初始化线程支持(Python 3.7+ 通常自动处理,但显式调用更安全)if(!PyEval_ThreadsInitialized()){PyEval_InitThreads();}// 释放 GIL,允许子线程运行 Python 代码// _save 指针必须保存,以便最后恢复 PyThreadState *_save =PyEval_SaveThread();//... 执行 QApplication::exec()...// 退出前恢复 GILPyEval_RestoreThread(_save);步骤 2:子线程获取与释放 GIL
任何工作线程(Worker Thread)在执行 Python 代码前,必须先获取 GIL,执行完毕后立即释放。推荐使用 pybind11 的 py::gil_scoped_acquire,这是一个 RAII 包装器,内部调用了 PyGILState_Ensure。
voidWorker::processData(){// 线程开始,尚未持有 GIL{// 获取 GIL py::gil_scoped_acquire acquire;// 安全地执行 Python 代码 py::module_ math = py::module_::import("math"); py::print(math.attr("sqrt")(16));}// 离开作用域,自动释放 GIL// 继续执行耗时的 C++ 计算(此时不阻塞其他 Python 线程)}这种“按需获取,用完即放”的策略最大限度地减少了 GIL 的持有时间,提高了并发效率。
7. 异常捕获与调试体系
当嵌入的 Python 代码抛出异常(如 ImportError、ValueError)时,如果 C++ 端不捕获,程序通常会直接终止。构建健壮的异常处理体系是工程化的关键。
7.1 C++ 端的异常转换
pybind11 会将 Python 异常捕获并转换为 C++ 异常 py::error_already_set。开发者应当在所有可能调用 Python 的边界处使用 try-catch 块。
try{ py::exec("import non_existent_module");}catch(const py::error_already_set &e){// e.what() 包含了异常类型和消息qCritical()<<"Python error occurred:"<< e.what();// 检查具体异常类型if(e.matches(PyExc_ImportError)){// 处理模块丢失逻辑}}7.2 获取完整 Traceback
仅获取错误消息(如 “division by zero”)往往不足以定位问题,开发者需要完整的调用堆栈(Traceback)。这可以通过在 C++ 中调用 Python 的 traceback 模块来实现。
QString getPythonTraceback(const py::error_already_set &e){// 必须先恢复 Python 错误状态,以便 traceback 模块能读取它 e.restore();try{ py::module_ tb = py::module_::import("traceback"); py::object format_exc = tb.attr("format_exc");// 获取格式化后的堆栈字符串 std::string trace =format_exc().cast<std::string>();returnQString::fromStdString(trace);}catch(...){return"Failed to generate traceback";}}结合 Qt 的日志系统,可以将这些 Traceback 输出到日志文件或弹窗显示,极大地方便了现场调试。
8. 发布与部署:跨越“DLL 地狱”
开发完成后的最后一道坎是部署。用户机器上可能没有 Python,或者版本不兼容。因此,自带私有 Python 环境(Bundling) 是最稳妥的策略。
8.1 Windows 部署策略
Python 官方提供了 Windows Embeddable Package (ZIP),这是专门为嵌入设计的最小化发行包。
部署步骤:
- 下载 ZIP:从 Python 官网下载对应版本(如 Python 3.9 Embeddable)。
- 解压:将 ZIP 内容解压到 Qt 应用程序的构建目录(例如 release/python 子目录,或者直接放在根目录)。
- 关键文件:确保 python3.dll 和 python3x.dll 与 MyApp.exe 同级,或在系统的 PATH 中。
- 配置路径文件 (._pth):嵌入版 Python 包含一个 python3xx._pth 文件。
- 这个文件强制指定了 sys.path,默认忽略环境变量 PYTHONPATH。
- 陷阱:如果不修改此文件,Python 无法导入 import site,导致 pip 安装的第三方库无法加载。
- 解决:编辑 ._pth 文件,取消最后一行 #import site 的注释,并添加 Lib/site-packages 等路径。
Qt 依赖处理:使用 windeployqt.exe 扫描应用程序,自动复制所需的 Qt DLL 和插件(如 platforms/qwindows.dll)24。最终的发布包应包含 Qt DLLs、Python DLLs、Python ZIP 包以及用户的脚本文件。
8.2 Linux 部署策略
Linux 的碎片化导致部署较为困难。用户系统的 /usr/lib/libpython3.so 可能与编译时不一致。
AppImage 方案:
推荐使用 linuxdeployqt 工具打包成 AppImage。
- 编译时链接到特定的 Python 库(建议编译静态版本的 Python 或将动态库复制到构建目录)。
- 在 AppImage 的 AppRun 脚本中,设置 PYTHONHOME 和 PYTHONPATH 环境变量,指向 AppImage 内部挂载的 Python 目录,屏蔽宿主机的 Python 环境。
9. 结论
Qt 与 Python 的混合编程并非简单的接口调用,而是一项涉及内存管理、类型系统映射、并发控制和工程化部署的系统性工程。
通过本报告的分析,得出以下核心结论:
- 架构选择:pybind11 是目前综合成本最低、性能最好的集成方案,适合绝大多数“C++ 为主,Python 为辅”的场景。
- 数据交互:通过自定义 type_caster 实现 QString 与 Python 字符串的透明转换,是提升代码可维护性的关键。
- 并发安全:严格遵循 GIL 管理协议(主线程释放,子线程获取),避免了多线程环境下的死锁陷阱。
- 独立部署:利用 Python Embeddable Package 和 windeployqt 构建自包含(Self-contained)的发布包,是确保软件在客户端稳定运行的基石。
这种混合架构既保留了 C++ 在工业级软件中的严谨与性能,又引入了 Python 生态的无限可能,是现代桌面应用开发的强大范式。
引用的著作
- What is the best way to embed python on a Qt/C++ applicattion [closed] : r/cpp - Reddit, 访问时间为 十一月 23, 2025, https://www.reddit.com/r/cpp/comments/hlabb3/what_is_the_best_way_to_embed_python_on_a_qtc/
- PyBind11 vs. PythonQt, embedding Python in C++ - YouTube, 访问时间为 十一月 23, 2025, https://www.youtube.com/watch?v=49Ur6EzqndM
- C/C++ and Python Programming with Qt Framework, OpenCV and Multi-Thread, 访问时间为 十一月 23, 2025, https://mevlutardic.medium.com/c-c-and-python-programming-with-qt-framework-opencv-and-multi-thread-4413a9735ce9
- Bridging the Gap between Python and C/C++ Libraries: An Exploration of Integrating with Cython, Ctypes, Pybind11, CFFI, and Python/C API | by Iftimie Alexandru | Medium, 访问时间为 十一月 23, 2025, https://medium.com/@iftimiealexandru/bridging-the-gap-between-python-and-c-c-libraries-an-exploration-of-integrating-with-cython-cc3bbfcfe539
- Python Bindings: Calling C or C++ From Python, 访问时间为 十一月 23, 2025, https://realpython.com/python-bindings-overview/
- 1. Embedding Python in Another Application — Python 3.14.0 documentation, 访问时间为 十一月 23, 2025, https://docs.python.org/3/extending/embedding.html
- convert cstring to python string object - Stack Overflow, 访问时间为 十一月 23, 2025, https://stackoverflow.com/questions/8494488/convert-cstring-to-python-string-object
- C API - How to return a Dictionary as a Dictionary type - Google Groups, 访问时间为 十一月 23, 2025, https://groups.google.com/g/comp.lang.python/c/9b2VYQgj0dw
- First steps - pybind11 documentation, 访问时间为 十一月 23, 2025, https://pybind11.readthedocs.io/en/stable/basics.html
- Embedding the interpreter - pybind11 documentation, 访问时间为 十一月 23, 2025, https://pybind11.readthedocs.io/en/stable/advanced/embedding.html
- call a Python function from c++ using pybind11 - Stack Overflow, 访问时间为 十一月 23, 2025, https://stackoverflow.com/questions/42521830/call-a-python-function-from-c-using-pybind11
- pybind/pybind11: Seamless operability between C++11 and Python - GitHub, 访问时间为 十一月 23, 2025, https://github.com/pybind/pybind11
- Strings, bytes and Unicode conversions - pybind11 documentation, 访问时间为 十一月 23, 2025, https://pybind11.readthedocs.io/en/stable/advanced/cast/strings.html
- pybind11 Documentation, 访问时间为 十一月 23, 2025, https://media.readthedocs.org/pdf/pybind11/stable/pybind11.pdf
- Custom type casters — pybind11 2.2.dev0 documentation - Read the Docs, 访问时间为 十一月 23, 2025, http://pybind11-jagerman.readthedocs.io/en/latest/advanced/cast/custom.html
- Custom type casters - pybind11 documentation, 访问时间为 十一月 23, 2025, https://pybind11.readthedocs.io/en/stable/advanced/cast/custom.html
- Embedding Python in a Qt Creator project - Stack Overflow, 访问时间为 十一月 23, 2025, https://stackoverflow.com/questions/59709725/embedding-python-in-a-qt-creator-project
- TASTE / shiboken6-demo - ESA GitLab, 访问时间为 十一月 23, 2025, https://gitlab.esa.int/taste/shiboken6-demo/-/tree/main
- Qt for Python/Shiboken - Qt Wiki, 访问时间为 十一月 23, 2025, https://wiki.qt.io/Qt_for_Python/Shiboken
- Qt for Python/GettingStarted - Qt Wiki, 访问时间为 十一月 23, 2025, https://wiki.qt.io/Qt_for_Python/GettingStarted
- Examples - Shiboken - Qt Documentation, 访问时间为 十一月 23, 2025, https://doc.qt.io/qtforpython-6/shiboken6/examples/index.html
- Embedding the Python Interpreter in a Qt/C++ Application - Ubuverse, 访问时间为 十一月 23, 2025, https://ubuverse.com/embedding-the-python-interpreter-in-a-qt-application/
- Include Python in Qt Creator - c++ - Stack Overflow, 访问时间为 十一月 23, 2025, https://stackoverflow.com/questions/31900560/include-python-in-qt-creator
- windeployqt fails with anaconda python - Stack Overflow, 访问时间为 十一月 23, 2025, https://stackoverflow.com/questions/42438147/windeployqt-fails-with-anaconda-python
- pybind/cmake_example: Example pybind11 module built with a CMake-based build system - GitHub, 访问时间为 十一月 23, 2025, https://github.com/pybind/cmake_example
- Debugging from within QT Creator · pybind pybind11 · Discussion #5481 - GitHub, 访问时间为 十一月 23, 2025, https://github.com/pybind/pybind11/discussions/5481
- makefile - How to embedding Python in C++ with PyBind and make instead of CMake?, 访问时间为 十一月 23, 2025, https://stackoverflow.com/questions/47678976/how-to-embedding-python-in-c-with-pybind-and-make-instead-of-cmake
- "Convert " Python to use QT project , qmake option error?, 访问时间为 十一月 23, 2025, https://discuss.python.org/t/convert-python-to-use-qt-project-qmake-option-error/27763
- call python from C++ with pybind11 - GitHub Gist, 访问时间为 十一月 23, 2025, https://gist.github.com/terasakisatoshi/79d1f656be9023cc649732c5162b3fc4
- How to deploy Qt application with embedded Python? - Qt Forum, 访问时间为 十一月 23, 2025, https://forum.qt.io/topic/67859/how-to-deploy-qt-application-with-embedded-python
- Convert std::string to QString - c++ - Stack Overflow, 访问时间为 十一月 23, 2025, https://stackoverflow.com/questions/4338067/convert-stdstring-to-qstring
- Python C++ interface - pybind11 documentation, 访问时间为 十一月 23, 2025, https://pybind11.readthedocs.io/en/stable/advanced/pycpp/index.html
- Python types - pybind11 documentation, 访问时间为 十一月 23, 2025, https://pybind11.readthedocs.io/en/stable/advanced/pycpp/object.html
- Deadlock when QThread tries to acquire Python GIL via PyGILState_Ensure(), 访问时间为 十一月 23, 2025, https://stackoverflow.com/questions/48005042/deadlock-when-qthread-tries-to-acquire-python-gil-via-pygilstate-ensure
- PyGILState_Ensure() Causing Deadlock - python - Stack Overflow, 访问时间为 十一月 23, 2025, https://stackoverflow.com/questions/47167251/pygilstate-ensure-causing-deadlock
- Does Python’s Global Interpreter Lock (GIL) affect QThreads? - Qt Forum, 访问时间为 十一月 23, 2025, https://forum.qt.io/topic/137322/does-python-s-global-interpreter-lock-gil-affect-qthreads
- `PyGILState_Ensure` in one thread causes the thread-local storage of other threads to be GCed · Issue #130394 · python/cpython - GitHub, 访问时间为 十一月 23, 2025, https://github.com/python/cpython/issues/130394
- How to get Python exception text - c++ - Stack Overflow, 访问时间为 十一月 23, 2025, https://stackoverflow.com/questions/1418015/how-to-get-python-exception-text
- Accessing a Python traceback from the C API - Stack Overflow, 访问时间为 十一月 23, 2025, https://stackoverflow.com/questions/1796510/accessing-a-python-traceback-from-the-c-api
- C++/embedded Python: Can I retrieve Python file name and line number when a C++ function is called from Python - Stack Overflow, 访问时间为 十一月 23, 2025, https://stackoverflow.com/questions/64334421/c-embedded-python-can-i-retrieve-python-file-name-and-line-number-when-a-c
- Deployment - Qt for Python, 访问时间为 十一月 23, 2025, https://doc.qt.io/qtforpython-6/deployment/index.html
- fully configuring embedded Python on Windows 10 - GitHub Gist, 访问时间为 十一月 23, 2025, https://gist.github.com/jtmoon79/ce63fe655b2f544462e70d8e5ec30ff5
- Embeddable python distro - Gamedev Guide, 访问时间为 十一月 23, 2025, https://ikrima.dev/ue4guide/python-basics/embeddable-python-distro/
- Deploy an Application on Windows - Qt Wiki, 访问时间为 十一月 23, 2025, https://wiki.qt.io/Deploy_an_Application_on_Windows
- Linuxdeployqt: New Linux Deployment Tool for Qt - Developers - AppImage, 访问时间为 十一月 23, 2025, https://discourse.appimage.org/t/linuxdeployqt-new-linux-deployment-tool-for-qt/57
- Packaging QT application to an .AppImage file for Linux - Stack Overflow, 访问时间为 十一月 23, 2025, https://stackoverflow.com/questions/71026584/packaging-qt-application-to-an-appimage-file-for-linux