I'm using PyQt4 and Python 2.7 to develop a plugin for QGIS 2.
I have QTableWidgets used to display/compare existing information in the database with newly entered information pertaining to the same feature. There are two QTableWidgets on a dialog box--when selecting a row in one table I would like to connect to one method, selecting a row in the other table would connect to another method. Pressing okay on the button box should accomplish tasks in each method, pressing cancel should roll back new edits.
I have two problems:
The first is an infinite loop, connecting repeatedly to the functions, and failure to close the dialog box and complete task whether okay, cancel, or close dialog is pushed. What's puzzling is that something different seems to happen each time--my guesses as to what may be going wrong: something to do with mixed up signals and slots, perhaps my function should return something so I can exit it.
The second, is that cancel doesn't destroyEditCommand(). There are times when destroyEditCommand doesn't work when okay is pushed for checkData() method.
In case this is important information, the buttonBox emits an accepted() signal to my plugin module in the accept() slot and rejected() signal to plugin module in the reject() slot. This was set up in PyQt4 designer.
Here are some pertinent parts of my code:
def updateTableWidget(self, fid): ... self.dlg.ui.maintTable.itemSelectionChanged.connect(self.updateData) self.dlg.ui.existTable.itemSelectionChanged.connect(self.checkData) … def updateData(self): QMessageBox.information(None, 'Connection Result', "In updateData method") result = self.dlg.exec_() if result == 1: self.myLayer.endEditCommand() QMessageBox.information(None, 'Whoopie PIE', "You have arrived at the terminal") else: self.myLayer.destroyEditCommand() def checkData(self): QMessageBox.information(None, 'Connection Result', "In checkData method") result = self.dlg.exec_() if result == 1: QMessageBox.information(None, 'Info', "Turn around and try again later") self.myLayer.destroyEditCommand() else: self.myLayer.destroyEditCommand()