Query regarding PythonQt

Shankar Narayana shank.nasa at gmail.com
Mon Jun 30 20:46:07 CEST 2008

  After a big fight, I could get through the problem. I am posting it so
that others does not waste  time solving the issue.
I dont know why "evalfile" method is having problems with existing .pyc
files. But, we can solve it this way.
First create your .cpp and .py file in <somedir> directory. Then, do the
1. Create somename.qrc file
 <!DOCTYPE RCC><RCC version="1.0">
 </RCC> 2. Navigate to the directory <somedir>. Type the command: qmake
-project (It creates project (.pro) file)
3. Next command: qmake (It creates a make file).
4. Then update the makefile  INCPATH to add for Python and Python-Qt
-I/usr/include/python2.5 -I/home/workspace/PythonQt-1.0/src
5. Update the LIBS  -L/usr/lib/python2.5/config/libpython2.5.a
-L/home/workspace/PythonQt-1.0/lib -lpython2.5 -lPythonQt
WARNING: Always use ":<pythonfilename>" in your cpp file eval command. Then
only Qrc will be used to create the corresponding. pyc file. Otherwise, the
terminal will crash.
Now issue the command "make" and run your application. Things work fine now.

I am not very clear with QRC but its a very good solution.


On Fri, Jun 27, 2008 at 2:41 PM, Shankar Narayana <shank.nasa at gmail.com>

> Hi,
>  I am newbie to PythonQt. I wanted to access the Qt objects created in C++
> using Python and update things. I had a look at this URL "
> http://doc.trolltech.com/qq/qq23-pythonqt.html#decoratorsandcwrappers"
> which talks about using PythonQt for the same.
>   I followed the instructions given in the example. I created my cpp file
> and .py file and could make them working.
>   But once after the first time after .pyc file is created, my program no
> longer executes. It is giving me a segmentation fault. If I remove my .pyc
> file and run the program, things work fine.
> My cpp file
> #include <QApplication>
> #include <QTextEdit>
> #include "PythonQt.h"
> int main(int argc, char* argv[])
> {
>     QApplication app(argc,argv);
>     QTextEdit *welcomemsg = new QTextEdit("Hi whatsup");
>     PythonQt::init();
>     PythonQtObjectPtr mainModule = PythonQt::self()->getMainModule();
>     mainModule.addObject("welcomemsg",welcomemsg);  // Check with different
> names
>     mainModule.evalFile("Pyscript.py");
>     mainModule.removeVariable("welcomemsg");
>     PythonQt::cleanup();
>     return app.exec();
> }
> My Python file  (Pyscript.py)
> from PythonQt import *
> #append the text to the existing text edit
> welcomemsg.append("Hurray I did it")
> welcomemsg.show()
> Can somebody help me what makes this not to run once Python interpreter
> works on the Python file and creates a .pyc file ?
> Regards,
> Shankar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080630/17f54e70/attachment.html>

More information about the Python-list mailing list