6

I have a QGIS (2.18.0) plugin which updates a join between to layer (spatial and non-spatial layer).

QGIS crashes when I run the plugin and the attribute table of the joined layer is open. There is no crash when the attribute table is closed or an attribute table of another layer is open.

The last two commands that the plugin runs are:

....
PUNKTE_OS.addJoin(joinObject)

PUNKTE_OS.triggerRepaint()
....

If there is no other solution, how can I close the attribute table of the joined layer before the new join is set?

I know, there is the showAttributeTable() method. Is there also a "closeAttributeTable()" method?

UPDATE:

It works when I close the specific attribute table in the def __init__(self, parent): function on Plugin startup. It doesn't work when I close the specific attribute table in the function where I set the joins (setJoin(self)).

Here a sample of my code:

class mask_n_functions(QDialog, Ui_Dialog):

def __init__(self, parent):
    QDialog.__init__(self, parent)
    self.setupUi(self)
    ...
    attrTables = [d for d in QApplication.instance().allWidgets() if d.objectName() == u'QgsAttributeTableDialog' or d.objectName() == u'AttributeTable' ]
    for x in attrTables:
        if 'attr_table' in x.windowTitle():
            x.close()

def setJoin(self):
    prjpath = QgsProject.instance().fileName()
    ...
5
  • If you have only one attribute table open:

    from PyQt4.QtGui import QApplication
    attrTables = [d for d in QApplication.instance().allWidgets() if d.objectName() == u'QgsAttributeTableDialog' or d.objectName() == u'AttributeTable']
    attrTables[0].close()
    

  • If you have multiple attribute tables open:

    from PyQt4.QtGui import QApplication
    attrTables = [d for d in QApplication.instance().allWidgets() if d.objectName() == u'QgsAttributeTableDialog' or d.objectName() == u'AttributeTable']
    for x in attrTables:
        x.close()
    

  • If you want to close specific attribute table(s):

    from PyQt4.QtGui import QApplication
    attrTables = [d for d in QApplication.instance().allWidgets() if d.objectName() == u'QgsAttributeTableDialog' or d.objectName() == u'AttributeTable' ]
    for x in attrTables:
        if 'PUNKTE' in x.windowTitle():
            x.close()
    
  • How can I close the attribute table of the layer "PUNKTE"? How can I get the names of the QDialog list attrTables? – Stefan Mar 10 '17 at 10:15
  • @Stefan - Edited my post to include an additional method. It's not a very direct method to closing attribute tables so I'm curious to see if there is a more efficient solution :). Note that the last method will close all attribute tables of layers which contains "PUNKTE" in their name. So ideally, you would want your layers to have unique names. – Joseph Mar 10 '17 at 10:33
  • I tried a lot of combinations (closing one, multiple or distinct attribute table), but nothing works. There must be a difference between, there is no attribute table open and closing attribute table with the plugin and the methods in your answer. It is strange, closing attribute table this way seems not like closing it "with hand" a priori. I tried also to refresh all layers in the canvas. – Stefan Mar 14 '17 at 12:19
  • @Stefan - Perhaps you can edit your question to include the code you used for joining the layers and attempting to remove the attribute table. – Joseph Mar 15 '17 at 9:42
  • It works when I close the specific attribute table in the def __init__(self, parent): function (calling plugin with panel). It doesn't work when I close the specific attribute table in the function where I set the joins. – Stefan Oct 5 '17 at 7:43

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.