QSqlTalbeModel 的问题。表格未显示
我有一个分配给表视图的 QsqlTableModel 。 我的问题是它没有填充表视图内的表。还是空的 它说(无法找到表格截图) - 打印 lastError.text() 时 -
函数retrieveShotResults..(检查下面的代码)是测试是否有一个名为shots的表,是的,它打印所有内容都很好,并且连接也很好..但表视图仍然是空的。 我做错了什么吗?
请帮忙
谢谢是提前
类 SqlModel(QtSql.QSqlTableModel):
def __init__(self):
super(SqlModel,self).__init__()
self.connect()
self.retrieveResult()
self.setEditStrategy(QtSql.QSqlTableModel.OnManualSubmit)
self.setTable("""shots""")
self.select()
def connect(self):
# dataBase connection
db = QSqlDatabase.addDatabase("QMYSQL")
db.setHostName("localhost")
db.setDatabaseName("magenta")
db.setUserName("admin")
db.setPassword("moayyad")
def retrieveShotResult(self):
query = QtSql.QSqlQuery()
query.exec_("""select * from shots""")
while query.next():
table = query.value(1).toString()
print table
i have a QsqlTableModel that is assigned to a table view .
my problem is that it doesn't populate the table inside the table view . it's still empty
and it says (Unable to find table shots) - when printing lastError.text() -
the function retrieveShotResults..(check code below) is to test if there is a table called shots and yes it prints everything just fine , and the connection is fine also .. but the table view is still empty .
am i doing anything wrong ?
please help
thanks is advance
class SqlModel(QtSql.QSqlTableModel):
def __init__(self):
super(SqlModel,self).__init__()
self.connect()
self.retrieveResult()
self.setEditStrategy(QtSql.QSqlTableModel.OnManualSubmit)
self.setTable("""shots""")
self.select()
def connect(self):
# dataBase connection
db = QSqlDatabase.addDatabase("QMYSQL")
db.setHostName("localhost")
db.setDatabaseName("magenta")
db.setUserName("admin")
db.setPassword("moayyad")
def retrieveShotResult(self):
query = QtSql.QSqlQuery()
query.exec_("""select * from shots""")
while query.next():
table = query.value(1).toString()
print table
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了^_^。应在主循环中调用 (connect) 函数
i found it ^_^ . the (connect) function should be called in the mainloop