python - [solved]resetItems PyQt - how to reload script -
python - [solved]resetItems PyQt - how to reload script -
this part of script. can't reload script (without stopping it) when info in file.txt changed.
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): homecoming stockdata @qtcore.pyqtslot(str) def resetitems(self, path): self.beginresetmodel() self.stockdata = self.stockdata #without , next line have same self.endresetmodel() #error if __name__ == '__main__': app = qtgui.qapplication(sys.argv) app.setstyle("plastique") tableview = qtgui.qtableview() tableview.show() = os.popen("cat /home/user/desktop/file.txt") = a.read() time_variable = qtcore.qstring("%s"%a) model = stocklistmodel([time_variable]) tableview.setmodel(model) sys.exit(app.exec_())
when run script , update file error: attributeerror: 'qstring' object has no attribute 'beginresetmodel'
what should alter refresh data?
you getting error because filechanged
signal of qfilesystemwatcher
emits string, beingness received resetitems()
, expecting instance of stocklistmodel
. self
reference doesn't passed because file_check
has been defined static , not bound particular instance.
try moving file_check
constructor instance variable , modifying resetitems()
take string parameter emitted filechanged
.
edit: added code clarity
constructor:
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)
resetitems:
@qtcore.pyqtslot(str) def resetitems(self, path): self.beginresetmodel() ...
python linux pyqt
Comments
Post a Comment