我正在用pyqt编写一个python代码,使用qtablewidget在mysql中显示表中的数据。我成功地从varchar表中获取了数据,但未能将整数获取并显示到qwidget中。你能看到我的代码并更正吗?
您能否告诉我如何获取时间戳信息,以及如何将其显示在qtable中?
from PyQt4.QtGui import *
from PyQt4.QtSql import *
import sys
def main():
app = QApplication(sys.argv)
table = QTableWidget()
db = QSqlDatabase.addDatabase("QMYSQL")
table.setWindowTitle("Connect to Mysql Database Example")
db.setHostName("127.0.0.1")
db.setDatabaseName("attendancemanagementsystem")
db.setUserName("root")
db.setPassword("password")
if (db.open() == False):
QMessageBox.critical(None, "Database Error",
db.lastError().text())
query = QSqlQuery("select * from users")
table.setColumnCount(query.record().count())
table.setRowCount(query.size())
index = 0
while (query.next()):
table.setItem(index, 0, QTableWidgetItem(query.value(0)))
table.setItem(index, 1, QTableWidgetItem(query.value(1)))
table.setItem(index, 2, QTableWidgetItem(query.value(2)))
index = index + 1
table.show()
return app.exec_()
if __name__ == '__main__':
暂无答案!
目前还没有任何答案,快来回答吧!