Please nominate your Qt Champions for 2021!

[solved] QAbstractListModel - update data in table view

  • How to update/refresh a data when my app is running. Data in 'file.txt' is changing, how to display this changes ?
    I don't want to shutdown and restart my app.

    @ class StockListModel(QtCore.QAbstractListModel):

    def __init__(self, stockdata = [], parent = None):
        QtCore.QAbstractListModel.__init__(self, parent)            
        self.__stockdata = stockdata            
    def rowCount(self, parent):
        return len(self.__stockdata)
    def data(self, index, role):        
        if role == QtCore.Qt.DisplayRole:
            row = index.row()
            value = self.__stockdata[row]
            return value

    if name == 'main':
    app = QtGui.QApplication(sys.argv)

    tableView = QtGui.QTableView() 
    a = os.popen("cat /home/user/file.txt")
    a =
    time_variable = QtCore.QString("%s"%a)       # how to refresh when app is running ?
    model = StockListModel([time_variable])

Log in to reply