【发布时间】:2021-04-30 06:15:03
【问题描述】:
我想在我的 QTableView 中显示数据库中所有可能的数据,但是错误
TypeError: QTableView(parent: QWidget = None): argument 1 has unexpected type 'int'
总是出现在最后。我不明白,因为我数据库中的所有数据类型都是 varchars 而不是 int。
这是我调用数据的函数:
def connectDB(self):
# TABLE
columns = ['Time In','Time Out', 'Class', 'Color', 'Specific Attribute', 'Camera Number']
tableWidget = QTableView(22, 6, self)
tableWidget.setHorizontalHeaderLabels(columns)
tableWidget.setGeometry( 400, 50, 850, 692)
tableWidget.resizeRowsToContents()
# CONNECTION
conn = mariadb.connect(
user="root",
password="",
host="localhost",
port=3306,
database="IRIS")
cur = conn.cursor()
cur.execute("SELECT * FROM iris_table")
allSQLRows= cur.fetchall()
tableWidget.setRowCount(len(allSQLRows))
data = [allSQLRows]
tableWidget.setModel(data)
【问题讨论】: