Bug report #18887
qgis-bin-g7.4.0.exe stopped working (python console)
Status: | Closed | ||
---|---|---|---|
Priority: | Normal | ||
Assignee: | - | ||
Category: | PyQGIS Console | ||
Affected QGIS version: | 3.0.2 | Regression?: | No |
Operating System: | Windows 10 | Easy fix?: | No |
Pull Request or Patch supplied: | No | Resolution: | invalid |
Crashes QGIS or corrupts data: | Yes | Copied to github as #: | 26719 |
Description
I got a crash when I used the python console to test some code. I attach below the code, simplified as much as possible to keep the entire crash reproductibility. It reproduces consistently in my QGIS 3.0.2 installation. The crash does not happen if the print function calls are removed.
Steps to reproduce:
1. Without opening any project, open directly Plugins>Python console
2. Paste the following code
class MyTable(QWidget): elements = [] def __init__(self, parent = None): QWidget.__init__(self, parent) self.layout = QVBoxLayout() self.setLayout(self.layout) self.button = QPushButton() self.button.setText('Find') self.button.clicked.connect(self.printElementWithFocus) self.layout.addWidget(self.button) self.addElement(0) def findElementWithFocus(self): for i, element in enumerate(self.elements): for child in element.findChildren(QWidget): if child is self.focusWidget(): return i def printElementWithFocus(self): print(self.focusWidget(), self.findElementWithFocus()) print(self.elements[0],self.elements[0].hasFocus()) def addElement(self, index): element = QLineEdit() self.elements.append(element) self.layout.insertWidget(0, element) dialog = QDialog() layout = QGridLayout() dialog.setLayout(layout) layout.addWidget(MyTable(), 0, 1, 1, 1) dialog.exec()
3. A dialog opens
4. Press the enter key and keep it pressed
5. In about 3 seconds, QGis crashes and Windows displays the message:
qgis-bin-g7.4.0.exe stopped working
History
#1 Updated by Nyall Dawson over 6 years ago
- Resolution set to invalid
- Status changed from Open to Closed
Solution is not to use print outside of console applications - use the safer QgsMessageLog class instead.