[PyKDE] [Fwd: embedding Qt and Python in one app]

Phil Thompson phil at river-bank.demon.co.uk
Mon Nov 20 11:28:37 GMT 2000


> Subject:
> Date: Fri, 17 Nov 2000 15:45:57 +0100
> From: "Floris van den Berg" <fb at magentammt.com>
> To: <thorsten at mats.gmd.de>
> 
> Hi there,
> 
> I have send this e-mail first to support at thekompany.com, but the e-mail
> address seems to be down. So i'm sending it to you. Hope you can help :)

Did your email bounce, or did you just get no reply?

> My question is regarding embedding Qt and Python in one app.
> 
> ----
> 
> I have successfully downloaded and installed your by the way excellent
> product.
> We want to use PyQt to embed Qt and Python in one application, where the
> 'cradle' is done in c++ under Windows (application consists of a
> QApplication and a QMainWindow) and several python scripts are done to make
> dialogs and such.
> 
> Using your product in the Python interpreter itself is no problem at all,
> but using it in an Qt app with an embedded python where one part of Qt is in
> c++ and one part is in python IS a problem. We have no idea how to go about
> this. We tried to recompile the library, using our own qt library, and to
> use the .lib that come out of it, but python still needs the libqt221.dll.
> And since there are no libs to links the DLL in c++, there are two seperate
> versions of Qt linked.

Sorry, I don't understand this last sentence. There shouldn't be any
problem re-building PyQt against your own Qt DLL - you may have to
change the name of the DLL in the Windows Makefile.

> In short, is there a way to rebuild the python module so that it uses our
> commercial version of Qt and - most important - is it possible to mix c++
> and python in a way that the cradle can be done in c++ and the other GUI
> elements in python? And in long, how?

You should be able to mix the two as you want (once you've got the build
problem sorted out). In your scripts use the qApp variable to access the
QApplication instance you created in C++ - and from that you use
mainWidget() to get at any other widgets you have created in C++.
Obviously, don't call exec_loop() - use your C++ one. The only problem
you might have is if you need access to any QApplication protected or
virtual methods - and you'll only ever be able to access the mainWidget
as a QWidget rather than a QMainWindow.

The other approach is to turn your C++ functionality into a Python
module (using SIP) and write your application as a Python script.

Phil




More information about the PyQt mailing list