test code for crash reports on mac

Mel Tearle mel.tearle at gmail.com
Mon Apr 22 04:31:29 BST 2024


Hello,

I found a better way to format the traceback so it’s
more like the built in one.

The vscode person didn’t have any the problem running this, 
but then again, they didn’t know what Rosetta was.

Thank you once more  for the suggestion.

Mel Tearle


import sys
import traceback

from PyQt6.QtCore import *
from PyQt6.QtGui import *
from PyQt6.QtWidgets import * 

class Window(QWidget):
def __init__(self):
super().__init__()
self.scene = QGraphicsScene(self)
self.view = QGraphicsView(self.scene)

self.scene.setSceneRect(0, 0, 400, 400)
## if you comment this line out and run this on a laptop without a mouse you should a qt.pointer.dispatch error
self.view.viewport().setAttribute(Qt.WidgetAttribute.WA_AcceptTouchEvents, False)
self.button = QPushButton("close")
self.button.clicked.connect(self.bye)
layout = QVBoxLayout(self)
layout.setAlignment(Qt.AlignmentFlag.AlignCenter)
layout.addWidget(self.view)
layout.addWidget(self.button)
self.setGeometry(550, 50, 400, 400)
self.show()

def bye(self):
1 + '1'
self.close()

def hook(type, value, tb): ## thanks to phil thompson and dev.to
err = '\t'.join(traceback.extract_tb(tb).format())
print(f'\n{type} \n{value} \n{err}')
sys.exit()

sys.excepthook = hook
if __name__ == '__main__':
app = QApplication(sys.argv)
test = Window()
sys.exit(app.exec())


More information about the PyQt mailing list