[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyQt] Memory leak when using QAbstractTableModel
From:       "Noam Raphael" <noamraph () gmail ! com>
Date:       2007-12-24 21:40:48
Message-ID: b348a0850712241340y3a6732b5rea9f2619071836a1 () mail ! gmail ! com
[Download RAW message or body]

Hurray! Thanks to Justin Noel on the qt-interest list, the following
code now works and doesn't leak!

Noam

===============
#!/usr/bin/env python

import sys
from PyQt4 import QtCore, QtGui
from PyQt4.QtCore import Qt

class TableModel(QtCore.QAbstractTableModel):
    def rowCount(self, index):
        return 1000 if not index.isValid() else 0

    def columnCount(self, index):
        return 1000 if not index.isValid() else 0

    def data(self, index, role):
        if index.isValid() and role == Qt.DisplayRole:
            return QtCore.QVariant(str((index.row(), index.column())))
        else:
            return QtCore.QVariant()

    def headerData(self, col, orientation, role):
        if orientation == Qt.Horizontal and role == Qt.DisplayRole:
            return QtCore.QVariant(str(col))
        if orientation == Qt.Vertical and role == Qt.DisplayRole:
            return QtCore.QVariant(str(col))
        return QtCore.QVariant()


def main():
    app = QtGui.QApplication(sys.argv)

    model = TableModel()
    tableView = QtGui.QTableView()
    tableView.setModel(model)

    tableView.show()
    sys.exit(app.exec_())

if __name__ == '__main__':
    main()
_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic