1

This is in reference to the similar question regarding QgsVectorLayerCache . The original code is taken from here

I'm trying to implement this method within the def run(self) method.

 def run(self):

    new_dialog = QDialog()

    new_dialog.resize(270, 210)

    layer = iface.activeLayer()
    canvas = iface.mapCanvas()
    feature_list_view = QgsFeatureListView(new_dialog)

    vector_layer_cache = QgsVectorLayerCache(layer, 1000)

    # for layer in QgsMapLayerRegistry.instance().mapLayers().values():
    #     if layer.name() == 'Pins':
    #         # pins_layer = layer
    #         self.pinLayer = layer
    #         self.provider = self.pinLayer.dataProvider()

    attribute_table_model = QgsAttributeTableModel(vector_layer_cache)

    attribute_table_model.loadLayer()
    attribute_table_filter_model = QgsAttributeTableFilterModel(
        canvas,
        attribute_table_model
    )
    feature_list_model = QgsFeatureListModel(attribute_table_filter_model)
    feature_list_model.setDisplayExpression('"Pins"')
    feature_list_view_delegate = QgsFeatureListViewDelegate(feature_list_model)
    feature_list_view.setModel(feature_list_model)
    # feature_list_view.setItemDelegate(feature_list_view_delegate) # Crash if uncommented. TODO: fix issue

    new_dialog.show()

Debugging it with PyCharm has revealed that this line here causes QGIS to crash:

vector_layer_cache = QgsVectorLayerCache(layer, 1000)

How can I put this in a proper function without causing a crash? QgsVectorLayerCache should still be availabe in QGIS 2.18 according to the API docu

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.