I'm using cx_Freeze to build my executable. I used Pyqt4 and the QtSql modules to display my database, the problem is when running through the python script, the database is displayed and the table works fine but when i run it as an executable the table does not work properly and nothing is displayed. When running as script: When running as an executable: Any reason as to why? Is this some bug for cx_Freeze?
Here is my code for creating the table:
self.ProductModel = QtSql.QSqlRelationalTableModel()
self.ProductModel.setTable("Product")
self.ProductModel.setRelation(6, QtSql.QSqlRelation("ProductType","ProductTypeID","Type"))
self.ProductModel.select()
fields = ["Product ID", "Product Name", "In Stock", "Expiry Date", "Stock Alert", "Price", "Product Type"]
for count in range(len(fields)):
self.ProductModel.setHeaderData(count, QtCore.Qt.Horizontal, fields[count])
edit = QtSql.QSqlTableModel.OnManualSubmit
self.ProductModel.setEditStrategy(edit)
self.ProductView = QtGui.QTableView()
self.ProductView.setModel(self.ProductModel)
self.ProductView.setSelectionMode(self.mode)
self.ProductView.setItemDelegate(ProductDelegate())
self.ProductView.sortByColumn(0,QtCore.Qt.AscendingOrder)
self.ProductView.setSortingEnabled(True)
There should be nothing wrong with this as everything works fine during the script.
and here's the setup script code for cx_Freeze:
from cx_Freeze import setup, Executable import sys import matplotlib
base = None if sys.platform == 'win32':
base = 'Win32GUI'
executables = [Executable("Main.py", base = base)] includes = ['matplotlib', 'PyQt4.QtSql'] setup(name = 'Test',
options = {"build_exe" : {"includes" : includes }},
version = '0.18',
description = 'Test',
executables = executables)