0

我正在从http://www.python.org/getit/运行 python 2.7.3 (python-2.7.3.amd64.msi)

我正在使用这些安装程序: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

我还尝试了来自以下位置的 pyqt 和 pyside 二进制文件:

我在以下 python 代码中收到错误“QSqlDatabase:未加载 QMYSQL 驱动程序”。我最好的猜测是上面的 pyside 和 pyqt 二进制安装程序没有构建 qt 以包含 QMYSQL?任何人都可以确认并且更重要的是,将我引导到构建了 QMYSQL 驱动程序的安装程序?我不准备尝试自己编译 qt 库。任何帮助表示赞赏。

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_()) 

这是gui代码:

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))
4

2 回答 2

1

关于 PySide,官方的 64 位 windows 安装程序(从 PySide 主页下载)确实只支持 QSQLITE 驱动程序。32 位安装程序支持 QSQLITE QODBC3 QODBC QPSQL7 QPSQL 驱动程序。R。

于 2013-04-11T08:52:18.923 回答
0

我决定使用 pyqt4 而不是 pyside,因为安装程序包含 QMYSQL 驱动程序。

于 2013-05-03T15:11:54.257 回答