[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)
    app.setStyle("plastique")

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

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.