python集成到应用中,将Python控制台集成到GUI C ++应用程序中

I'm going to add a python console widget (into a C++ GUI) below some other controls:

11e64520f08158373c787b1ad774cf58.png

Many classes are going to be exposed to the python code, including some access to GUI (maybe I'll consider PyQt).

Should I run the Python code in a separate thread?

I think it's a good approach, because GUI won't be frozen while executing long commands. But on the other hand, shouldn't other controls be disabled to preserve objects' state and avoid conflicts?

解决方案

Since you're apparently wanting to embed a Python interpreter to use Python as a scripting language in a what seems to be a Qt application, I suggest you have a look at PythonQt.

With the PythonQt module, Python scripts will be able to interact with the GUI of your host application.

Unlike PyQt and Qt Jambi, PythonQt is not designed to provide support for developers writing standalone applications. Instead, it provides facilities to embed a Python interpreter and focuses on making it easy to expose parts of the application to Python.

If I understood your needs correctly, that's all you need.

PyQt and PySide (officially supported by Nokia) aim at accessing Qt features from a Python program by providing bindings.

It's possible to embed PyQt in your application (even a Qt application) and your Python scripts will be able to provide their own GUI while interacting with your application scripting API.

About thread safety, Qt offers a thread-safe way of posting events, and signal-slot connections across threads.

References:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值