Hi Radosław,

Things like this are most likely introduced by loosing the reference to objects which then get garbage collected.

Try assigning the objects to local variables. I.e. change "model" to "self.model", "filterModel" to "self.filterModel" etc.

Hope this helps
Matthias

On Sun 19 Jan 2014 04:18:09 PM CET, Radosław Pasiok wrote:
Hello Devs!

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.

There is no problem when I use QGIS python console:

from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
from qgis.gui import *
w = QMainWindow()
cw = QWidget(w)
gridLayout = QGridLayout(cw)
w.setCentralWidget(cw)
tv = QgsAttributeTableView(cw)
gridLayout.addWidget(tv, 0, 0, 1, 1)
xs = iface.mapCanvas().currentLayer()
xsCache = QgsVectorLayerCache(xs, 10)
model = QgsAttributeTableModel(xsCache)
model.loadLayer()
filterModel = QgsAttributeTableFilterModel(iface.mapCanvas(), model)
tv.setModel(filterModel)
w.show()

When using the some code in a plugin :

class TableViewDialog(QMainWindow):
    def __init__(self, parent, iface):
        QMainWindow.__init__(self)
        self.ui = Ui_TableView()
        self.ui.setupUi(self)
        self.iface = iface
        self.ui.refreshButton.clicked.connect(self.refresh)

    def refresh(self):
        tv = self.ui.tableView
        xs = self.iface.mapCanvas().currentLayer()
        xsCache = QgsVectorLayerCache(xs, 10)
        model = QgsAttributeTableModel(xsCache)
        model.loadLayer()
        filterModel =
QgsAttributeTableFilterModel(self.iface.mapCanvas(), model)
        tv.setModel(filterModel)

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'.
What could make the difference between those two cases. Am I missing
something in the plugin code?

Thank you for any hint!

Radek



--
Używam wolnego oprogramowania:
http://www.gnu.org/philosophy/philosophy.pl.html


_______________________________________________
Qgis-developer mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/qgis-developer


_______________________________________________
Qgis-developer mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/qgis-developer

Reply via email to