<div dir="ltr"><div>Hello Devs!<br><br></div>I would like to ask you for help with using a QgsAttributeTableView in a plugin. I am using QGIS-master on Ubuntu 12.04 but the same applies to QGIS-dev from OSGeo4W.<br><br>There is no problem when I use QGIS python console:<br>
<br>from PyQt4.QtCore import *<br>from PyQt4.QtGui import *<br>
from qgis.core import *<br>from qgis.gui import *<br>w = QMainWindow()<br>cw = QWidget(w)<br>gridLayout = QGridLayout(cw)<br>w.setCentralWidget(cw)<br>tv = QgsAttributeTableView(cw)<br>gridLayout.addWidget(tv, 0, 0, 1, 1)<br>

xs = iface.mapCanvas().currentLayer()<br>xsCache = QgsVectorLayerCache(xs, 10)<br>model = QgsAttributeTableModel(xsCache)<br>model.loadLayer()<br>filterModel = QgsAttributeTableFilterModel(iface.mapCanvas(), model)<br>tv.setModel(filterModel)<br>

w.show()<br clear="all"><div><div><br></div><div>When using the some code in a plugin :<br><br>class TableViewDialog(QMainWindow):<br>    def __init__(self, parent, iface):<br>        QMainWindow.__init__(self)<br>        self.ui = Ui_TableView()<br>
        self.ui.setupUi(self)<br>        self.iface = iface<br>        self.ui.refreshButton.clicked.connect(self.refresh)<br>    <br>    def refresh(self):<br>        tv = self.ui.tableView<br>        xs = self.iface.mapCanvas().currentLayer()<br>
        xsCache = QgsVectorLayerCache(xs, 10)<br>        model = QgsAttributeTableModel(xsCache)<br>        model.loadLayer()<br>        filterModel = QgsAttributeTableFilterModel(self.iface.mapCanvas(), model)<br>        tv.setModel(filterModel)<br>
<br>I cannot get the table populated with features and QGIS crashes occasionally when refresh() is called. The tableView object is promoted to QgsAttributeTableView with header 'qgis.gui'.<br></div><div>What could make the difference between those two cases. Am I missing something in the plugin code?<br>
</div><div><br></div><div>Thank you for any hint!<br><br></div><div>Radek<br></div><div><br><br><br></div><div>-- <br>Używam wolnego oprogramowania: <br><a href="http://www.gnu.org/philosophy/philosophy.pl.html" target="_blank">http://www.gnu.org/philosophy/philosophy.pl.html</a>
</div></div></div>