[PyQt] Fwd: Re: c++ app integrate PyQt

John Fabiani johnf at jfcomputer.com
Tue Oct 1 03:05:55 BST 2013


On 09/30/2013 06:36 PM, Glenn Ramsey wrote:
> On 01/10/13 14:22, John Fabiani wrote:
>> On 09/30/2013 06:11 PM, John Fabiani wrote:
>>>
>>>
>>>
>>> -------- Original Message --------
>>> Subject:     Re: [PyQt] c++ app integrate PyQt
>>> Date:     Mon, 30 Sep 2013 17:51:28 -0700
>>> From:     John Fabiani <johnf at jfcomputer.com>
>>> To:     Matt Newell <newellm at blur.com>
>>>
>>>
>>>
>>> On 09/30/2013 05:24 PM, Matt Newell wrote:
>>> > On Monday, September 30, 2013 04:51:24 PM John Fabiani wrote:
>>> >> Hi,
>>> >> I have an existing Qt C++ app (Qt5.1.1).  Is it possible to 
>>> integrate
>>> >> PyQt into the project.  I'd like the PyQt to have access to some 
>>> of the
>>> >> C++ functions, C++ classes, but I want to write frames,windows, 
>>> all the
>>> >> controls in PyQt including accessing the database. Most important I
>>> >> want only one app loop.  I was able in get PythonQt working but 
>>> realized
>>> >> that it was a lot of work to get it to do what I want - that is to
>>> >> create a complete sub-program written in python.
>>> >>
>>> >>
>>> >> Any hints or links will be helpful.
>>> >>
>>> >> Thankis in advance,
>>> >>
>>> >>
>>> >> Johnf
>>> >
>>> > Yes it's possible.  You have to wrap any c++ classes you want to 
>>> use from
>>> > python using sip.  Then you need to embed python in your app, or 
>>> rewrite the
>>> > main part of the application in python.
>>> >
>>> > You'll want to first split your app into a library so you can test 
>>> your python
>>> > bindings from a regular python script or cmd interpreter.  Start 
>>> with one
>>> > class to get your feet wet and go from there.
>>> >
>>> > Matt
>>> That sounds encouraging.  But it lacks a little detail - like how does
>>> one embed python (PyQt) into a C++ app.  The sip I sort of understand
>>> and it is doable.  I only need a few C++ classes and that makes sense.
>>> But I don't have a clue how or where to start on embeding PyQt.  Does
>>> someone have an example or a link explaining the details.
>>>
>>> Johnf
>> Write the right phrase in a google search and you find things. But I 
>> wonder if
>> this the best solution?  It's also old.
>> http://acaciaecho.wordpress.com/2011/08/15/hybridqtwithpyqt/
>>
>> Anyone, have opinion?
>>
>> Johnf
>
> From your spec (writing all of the GUI in PyQt) it sounds like you 
> should be writing your C++ components as Python extension modules 
> rather than embedding a Python interpreter in your app.
>
> There are several ways to do that: SIP, SWIG, Boost.Python.
>
> Also if you do this then your app will play nicely with packaging 
> tools like Py2exe and PyInstaller. If you have .ui files you should be 
> able to reuse them with minimal or no changes.
>
> Glenn
>
Sorry if I mis-led you somewhere.  The C++ app has been around for many 
years and is NOT going to be rewritten anytime soon.  I want to 
integrate a python solution that will allow me to create new content 
using python all running within the C++ app loop.  I'm hoping I can do 
it with PyQt.  Creating the library would work - it would allow me to 
test and work in python.  There are only a few things I need the python 
to know about from the C++ side - the login data, a couple of pieces of 
data, and one Class.  After those minor things I don't need a thing.   
That said, it would be nice if the python side could call up some of the 
C++ forms.

Johnf



More information about the PyQt mailing list