在这种情况下,我通过XAMPP从phpMyAdmin使用Python 3.5,PyQt5和我的本地数据库。我想将我的数据库加载到我的QTableView
对象并执行SQL查询,但没有任何作用。
db = QSqlDatabase.addDatabase('QSQLITE')
db.setHostName('localhost')
db.setPort(3306)
db.setDatabaseName('myDatabase')
db.setUserName('root@localhost')
query = QSqlQuery(db)
query.exec_('select column2 from form;')
model = QSqlTableModel()
self.initializeModel(model) #self.initializeModel() is a self-made function
view = self.createView(model) #self.createView is also a self-made
#function that creates my QTableView object
self.grid.addWidget(view, 0, 0)