I am running python 2.7.3 (python-2.7.3.amd64.msi) from http://www.python.org/getit/
I am using these installers from: http://www.lfd.uci.edu/~gohlke/pythonlibs/
- PyQt-Py2.7-x64-gpl-4.9.6-1.exe
- PySide-1.1.2.win-amd64-py2.7.exe
- MySQL-python-1.2.4.win-amd64-py2.7.exe
I also tried the pyqt and pyside binaries from:
- http://www.riverbankcomputing.com/software/pyqt/download
- http://qt-project.org/wiki/PySide_Binaries_Windows
I am getting the error "QSqlDatabase: QMYSQL driver not loaded" in the following python code. My best guess is that the pyside and pyqt binary installers above did not build qt to include QMYSQL? Can anyone confirm that AND more importantly, direct me to an installer that has the QMYSQL driver built? I am not prepared to attempt compiling the qt library myself. Any help is appreciated.
import sys
from showrec import * # import qtdesigner ui (converted using pyside-uic)
from PySide import QtGui, QtSql
#===================================================================
#
#===================================================================
def createConnection():
db = QtSql.QSqlDatabase.addDatabase('QMYSQL')
db.setHostName('localhost')
db.setDatabaseName('mydatabase')
db.setUserName('userid')
db.setPassword('password')
db.open()
print (db.lastError().text())
return True
#===================================================================
#
#===================================================================
class MyForm(QtGui.QDialog):
def __init__(self, parent=None):
#super(MyForm, self).__init__(parent) # I suspect this is needed?
QtGui.QWidget.__init__(self,parent)
self.ui = Ui_Dialog()
self.ui.setupUi(self)
self.model = QtSql.QSqlDatabase(self)
self.model.setTable("products")
self.model.setEditStrategy(QtSql.QSqlTableModel.OnManualSubmit)
self.model.select()
self.ui.tableView.setModel(self.model)
#===================================================================
# main
#===================================================================
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
if not createConnection():
sys.exit(1)
myapp = MyForm()
myapp.show()
sys.exit(app.exec_())
This the the gui code:
from PySide import QtCore, QtGui
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(400, 300)
self.tableView = QtGui.QTableView(Dialog)
self.tableView.setGeometry(QtCore.QRect(20, 20, 256, 192))
self.tableView.setObjectName("tableView")
self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
Dialog.setWindowTitle(QtGui.QApplication.translate("Dialog", "Dialog", None, QtGui.QApplication.UnicodeUTF8))