gpt4 book ai didi

python - beginResetModel() - 不起作用

转载 作者:太空宇宙 更新时间:2023-11-04 03:56:53 24 4
gpt4 key购买 nike

当脚本运行时,我正在更改文件的内容。在 centos 上我遇到了这样的错误:

AttributeError: 'list' object has no attribute 'beginResetModel'

在 Ubuntu 上,我没有任何错误,但 srcipt 没有重新加载数据。在这种情况下它可能与 beginResetModel 有关吗?

class StockListModel(QtCore.QAbstractListModel):
def __init__(self, stockdata = [], parent = None):
QtCore.QAbstractListModel.__init__(self, parent)
self.stockdata = stockdata
self.file_check = QtCore.QFileSystemWatcher(['/home/user/Desktop/file.txt'])
self.file_check.fileChanged.connect(self.resetItems)

def getItems(self):
return self.stockdata

@QtCore.pyqtSlot(str)
def resetItems(self, path):
self.beginResetModel()
self.stockdata = self.stockdata
self.endResetModel()

if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
app.setStyle("plastique")

tableView = QtGui.QTableView()
tableView.show()

file = open('/home/user/Desktop/file.txt')
a = file.readline() # ------> type STRING
time_variable = QtCore.QString("%s"%a)

model = StockListModel([time_variable])

tableView.setModel(model)
sys.exit(app.exec_())

最佳答案

重置模型时您不会更改数据:

self.stockdata = self.stockdata

此行需要将 self.stockdata 设置为更新后的值。大概您想从您正在观看的文件中读取更改。

关于python - beginResetModel() - 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24410025/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com