我正在使用QTableView并尝试获取列中的所有值。能够使用下面的代码检索值
data= []
for row in range(model.rowCount()):
data.append([])
for column in range(model.columnCount()):
index = model.index(row, 0)
data[row].append(str(model.data(index)))
for item in data:
names = '{}'.format(item[0])
print(names)
面临的问题是我将值作为字节获取,例如
b'Austria'
b'Belgium'
b'Denmark'
b'England'
b'Finland'
而不是
Austria
Belgium
Denmark
England
Finland
答案 0 :(得分:1)
以下是解决问题的工作代码
names = []
data = []
for row in range(model.rowCount()):
name = model.data(model.index(row, 0))
data.append((name))
names.append(name)
for name in names:
decoded_name = bytes(name).decode()
print(decoded_name)