简体   繁体   English

在Qt C ++应用程序中创建python解释器小部件的简单方法?

[英]Easy way to create a python interpreter widget in a Qt C++ app?

My app is written in C++. 我的应用程序是用C ++编写的。 I use Qt for the GUI. 我使用Qt作为GUI。 I have built python bindings for the the core of my app. 我为我的应用程序的核心构建了python绑定。

I would like to create an interpreter widget that would let the user access an embedded python interpreter where they can use my own python bindings to script operations available in the app. 我想创建一个解释器小部件,让用户访问一个嵌入式python解释器,在那里他们可以使用我自己的python绑定来编写应用程序中可用的脚本操作。

The widgets I've been able to find online all assume one is using PyQt, but I want to do this in straight C++/Qt. 我在网上找到的小部件都假设有一个使用PyQt,但我想用直接的C ++ / Qt来做。 Has anybody developed a Qt widget in C++ that I could reuse? 有人用C ++开发了一个我可以重用的Qt小部件吗?

AFAIK Qt does not provide a way to do that right now through a standard Qt component, there is a library called PythonQt that tries to accomplish what you need, but it only supports Qt 4. If that is acceptable then go for it, otherwise, you should download the python source code, compile it and then start here to see how to embed the interpreter in your application. AFAIK Qt现在没有提供通过标准Qt组件实现这一目的的方法,有一个名为PythonQt的库试图完成你需要的东西,但它只支持Qt 4.如果这是可以接受的,那就去吧,否则,你应该下载python源代码,编译它然后从这里开始看看如何在你的应用程序中嵌入解释器。

If you also want to expose parts of your application to the interpreter, you will have to use the Python C api to create a wrapper, you might be able to use SWIG to minimize the amount of work you have to do 如果您还想将部分应用程序暴露给解释器,则必须使用Python C api创建包装器,您可以使用SWIG来最小化您必须执行的工作量

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM