[PyQt] Problems with pyInstaller 2.0 and qt setWindowIcon Command

Hans-Peter Jansen hpj at urpla.net
Wed Nov 14 15:44:39 GMT 2012


Am Mittwoch, 14. November 2012, 12:57:05 schrieb James Goss:
> Hi All,
> 
> 
> Wondering if anyone can help,
> 
> Simple Qt Application:
> |from  PyQt4  import  QtGui,  QtCore
> 
> import  sys,  atexit
> 
> class  ApplicationWindow(QtGui.QMainWindow):
>      def  __init__(self):
>          QtGui.QMainWindow.__init__(self)
>          self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
>          self.setWindowTitle("application main window")
>          self.file_menu=  QtGui.QMenu('&File',  self)
>          self.menuBar().addMenu(self.file_menu)
>          self.menuBar().addSeparator()
> 
>          self.main_widget=  QtGui.QWidget(self)
> 
> qApp=  QtGui.QApplication(sys.argv)
> aw=  ApplicationWindow()
> aw.show()
> sys.exit(qApp.exec_())
> qApp.exec_()|
> 
> Run's without a problem and I can build an exe using pyInstaller which
> also runs fine.
> 
> I add the lines:
> |iconfile=  QtGui.QIcon('C:/pyinstaller/img/image1.png')
> 
> aw.setWindowIcon()  |
> 
> Just before aw.show() (also tried in other places throughout the code)
> 
> This run's fine as a python file but when built using pyInstaller the
> exe crashes at run-time, I've tried using resource files and other image
> formats but the problem remains.

Of course, you _need_ to use a resource file, that you compile with pyrcc4
and import accordingly. E.g.

import test_rc
[...]
	iconfile = QtGui.QIcon(':/image1.png')


The test.qrc may look like:

<RCC>
  <qresource>
    <file alias="image1.png">img/image1.png</file>
  </qresource>
</RCC>

pyrcc4 -o test_rc.py test.qrc

Having all resources included in one executable is the reason for pyinstallers 
existence..

Hth,
Pete
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20121114/641c4559/attachment.html>


More information about the PyQt mailing list