Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [solved] QAbstractListModel - update data in table view
Forum Updated to NodeBB v4.3 + New Features

[solved] QAbstractListModel - update data in table view

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 1.2k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    s_z_p
    wrote on last edited by
    #1

    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_())@
    
    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved