[Baypiggies] Is it problematic to embed python in a Qt C++ app?
ken at seehart.com
Mon Jan 15 21:24:23 CET 2007
craig harris wrote:
> HI all,
> I have a C++ Qt based app and am creating a text API for its
> functions. It would work as follows: A Qt command console would
> allow users to type in text. Then that text would be parsed by
> python. The python would wrap C++ functions and execute them.
> Before I try to do this, I was wondering if anyone had advice
> 'against' or 'for' this approach? Is it problematic?
> I guesss another way of asking: can you simaltaneously embed python in
> C++ and C++ in python?
To answer your second way of asking: Yes. In fact, projects involving
*embedding *almost always involve *extending *as well, (otherwise adding
python would probably not be very helpful except maybe as a built in
calculator) :-) .
Some terminology to help readers follow this:
*extending *= wrapping your C/C++ code in python (thereby making your
application's internals available to python code)
*embedding *= making the python interpreter available to the end user
(thereby allowing the end user to write python code)
See also: http://docs.python.org/ext/ext.html
I don't know much about QT, but I can't imagine any problems being
created by QT with respect to extending and embedding (especially given
the success of PyQT), so I can say with 99.742% certainty that it will
work fine. I'm a wxPython guy.
It is much better to write the entire user interface in python (PyQT or
wxPython, etc) in the first place, but if you already have a working GUI
in C++ it definitely makes sense to embed python.
BTW, the only overwhelming reason to favor C++ over python for any /new
/GUI development is because management thinks it's a good idea and you
really don't want to annoy them with newfangled ideas. Another
advantage of writing GUI code in C++ instead of python is that it takes
4 to 10 times as long to implement C++, which is very good for job
- Ken Seehart
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Baypiggies