[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: Possible Pyqt6 Bug for MacOS
From:       Phil Thompson <phil () riverbankcomputing ! com>
Date:       2024-02-08 21:43:48
Message-ID: fb17e8897b4d689121880c3df947b2a8 () riverbankcomputing ! com
[Download RAW message or body]

On 08/02/2024 19:29, Bob Shotwell wrote:
> Hi,
> I am developing a Python application to assist in the creation of
> Python applications.  The core system has been working for about a
> year.  Several months ago, I started getting a C++ error messages in
> my python application running in PyCharm.
> 
> After some significant amount of troubleshooting, I have come to
> suspect that the error is coming from Pyqt6.  Here is what I have
> learned.  The following terminal commands describe my operating
> environment.
> 
> bobshotwell@Bobs-Mac-Studio ~ % sw_vers
> ProductName:           macOS
> ProductVersion:        14.2.1
> BuildVersion:          23C71
> bobshotwell@Bobs-Mac-Studio ~ % python3
> Python 3.12.1 (v3.12.1:2305ca5144, Dec  7 2023, 17:23:38) [Clang
> 13.0.0 (clang-1300.0.29.30)] on darwin
> Type "help", "copyright", "credits" or "license" for more information.
> > > > import PyQt6.QtCore
> > > > print(PyQt6.QtCore.PYQT_VERSION_STR)
> 6.6.1
> > > > 
> 
> I did not include info about PyCharm since I have replicated the error
> running python3 in the terminal.
> 
> Because of the complexity of my application, I used ChatGPT 4.0 to
> replicate the problem with a simple demo script.
> 
> I issued the following ChatGPT 4.0 prompt:
> 
> Create a python script to implement the following specification. The
> script uses Pyqt6 to implement the UI. The script has two widgets.
> Widget 1 is a combobox. Initially, the combo box is loaded from the
> following tuple ('alice', 'bob', 'charlie'). Widget 2 is a pushbutton.
> When the pushbutton is clicked, the contents of the combobox are
> toggled between the initial tuple and the following tuple {'drew',
> 'eric', 'fred').
> 
> ChatGPT 4.0 generated the following script:
> 
> import sys
> from PyQt6.QtWidgets import QApplication, QMainWindow, QVBoxLayout,
> QWidget, QComboBox, QPushButton
> 
> class MainWindow(QMainWindow):
> def __init__(self):
> super().__init__()
> 
> # Initial and alternate tuples for the combobox
> self.initial_tuple = ('alice', 'bob', 'charlie')
> self.alternate_tuple = ('drew', 'eric', 'fred')
> 
> self.setWindowTitle("Toggle Combobox Contents")
> self.setGeometry(100, 100, 200, 100)
> 
> # Create the combobox and populate it with the initial tuple
> self.comboBox = QComboBox()
> self.comboBox.addItems(self.initial_tuple)
> 
> # Create the pushbutton
> self.pushButton = QPushButton("Toggle List")
> self.pushButton.clicked.connect(self.toggle_combobox_contents)
> 
> # Layout configuration
> layout = QVBoxLayout()
> layout.addWidget(self.comboBox)
> layout.addWidget(self.pushButton)
> 
> centralWidget = QWidget()
> centralWidget.setLayout(layout)
> self.setCentralWidget(centralWidget)
> 
> def toggle_combobox_contents(self):
> # Check current items in the combobox to determine which tuple 
> to use
> current_items = [self.comboBox.itemText(i) for i in
> range(self.comboBox.count())]
> if tuple(current_items) == self.initial_tuple:
> self.comboBox.clear()
> self.comboBox.addItems(self.alternate_tuple)
> else:
> self.comboBox.clear()
> self.comboBox.addItems(self.initial_tuple)
> 
> def main():
> app = QApplication(sys.argv)
> mainWindow = MainWindow()
> mainWindow.show()
> sys.exit(app.exec())
> 
> if __name__ == "__main__":
> main()
> 
> I copied this script into a .py file (demo.py) and ran it in the 
> terminal:
> 
> bobshotwell@Bobs-Mac-Studio ~ % cd documents
> bobshotwell@Bobs-Mac-Studio documents % nano demo.py
> bobshotwell@Bobs-Mac-Studio documents % python3 demo.py
> 
> The script starts up without a problem.  However, when the pushbutton
> is clicked, the statement at line 37
> ("self.comboBox.addItems(self.alternate_tuple)") throws the following
> error:
> 
> *** Terminating app due to uncaught exception 'NSRangeException',
> reason: '*** -[__NSArrayM objectAtIndexedSubscript:]: index 0 beyond
> bounds for empty array'
> *** First throw call stack:
> (
> 0   CoreFoundation                      0x000000018806c570
> __exceptionPreprocess + 176
> 1   libobjc.A.dylib                     0x0000000187b5deb4
> objc_exception_throw + 60
> 2   CoreFoundation                      0x0000000187fe2d10
> -[__NSCFString hasSuffix:] + 0
> 3   libqcocoa.dylib                     0x00000001075c6044
> _ZN20QCocoaSystemTrayIcon13emitActivatedEv + 274796
> 4   libqcocoa.dylib                     0x00000001075c60c8
> _ZN20QCocoaSystemTrayIcon13emitActivatedEv + 274928
> 5   libqcocoa.dylib                     0x00000001075c4688
> _ZN20QCocoaSystemTrayIcon13emitActivatedEv + 268208
> 6   QtWidgets                           0x0000000105b191a8
> _ZN9QListView16selectionChangedERK14QItemSelectionS2_ + 204
> 7   QtCore                              0x0000000106fd348c
> _ZN11QMetaObject8activateEP7QObjectPKS_iPPv + 3808
> 8   QtCore                              0x0000000107199e44
> _ZN19QItemSelectionModel20emitSelectionChangedERK14QItemSelectionS2_ +
> 216
> 9   QtCore                              0x0000000107199a2c
> _ZN19QItemSelectionModel6selectERK14QItemSelection6QFlagsINS_13SelectionFlagEE
>  + 636
> 10  QtCore                              0x000000010719970c
> _ZN19QItemSelectionModel6selectERK11QModelIndex6QFlagsINS_13SelectionFlagEE
>  + 68
> 11  QtCore                              0x000000010719a8cc
> _ZN19QItemSelectionModel15setCurrentIndexERK11QModelIndex6QFlagsINS_13SelectionFlagEE
>  + 260
> 12  QtWidgets                           0x0000000105977338
> _ZNK9QComboBox5countEv + 828
> 13  QtWidgets                           0x000000010597a8b4
> _ZN9QComboBoxC1ER16QComboBoxPrivateP7QWidget + 2412
> 14  QtCore                              0x0000000106fd3224
> _ZN11QMetaObject8activateEP7QObjectPKS_iPPv + 3192
> 15  QtCore                              0x0000000107182944
> _ZN18QAbstractItemModel13endInsertRowsEv + 200
> 16  QtGui                               0x000000010798f1a8
> _ZN18QStandardItemModel11itemChangedEP13QStandardItem + 844
> 17  QtWidgets                           0x000000010597de38
> _ZN9QComboBox11insertItemsEiRK5QListI7QStringE + 340
> 18  QtWidgets.abi3.so                   0x0000000106b529bc
> _ZL23meth_QComboBox_addItemsP7_objectS0_ + 136
> 19  Python                              0x00000001062722ec
> cfunction_call + 108
> 20  Python                              0x0000000106203378
> _PyObject_MakeTpCall + 128
> 21  Python                              0x0000000106348a40
> _PyEval_EvalFrameDefault + 47144
> 22  Python                              0x000000010620748c
> method_vectorcall + 368
> 23  QtCore.abi3.so                      0x00000001054be418
> _ZNK8PyQtSlot4callEP7_objectS1_ + 156
> 24  QtCore.abi3.so                      0x00000001054be22c
> _ZNK8PyQtSlot6invokeEPPvP7_objectS0_b + 296
> 25  QtCore.abi3.so                      0x00000001054bf200
> _ZN13PyQtSlotProxy7unislotEPPv + 92
> 26  QtCore.abi3.so                      0x00000001054bf170
> _ZN13PyQtSlotProxy11qt_metacallEN11QMetaObject4CallEiPPv + 68
> 27  QtCore                              0x0000000106fd31f4
> _ZN11QMetaObject8activateEP7QObjectPKS_iPPv + 3144
> 28  QtWidgets                           0x0000000105960ec8
> _ZNK15QAbstractButton11isCheckableEv + 816
> 29  QtWidgets                           0x0000000105960d48
> _ZNK15QAbstractButton11isCheckableEv + 432
> 30  QtWidgets                           0x0000000105961c48
> _ZN15QAbstractButton17mouseReleaseEventEP11QMouseEvent + 172
> 31  QtWidgets.abi3.so                   0x0000000106a399ec
> _ZN14sipQPushButton17mouseReleaseEventEP11QMouseEvent + 148
> 32  QtWidgets                           0x00000001058ad8b8
> _ZN7QWidget5eventEP6QEvent + 132
> 33  QtWidgets                           0x0000000105a0eb24
> _ZN11QPushButton5eventEP6QEvent + 204
> 34  QtWidgets.abi3.so                   0x0000000106a3a41c
> _ZN14sipQPushButton5eventEP6QEvent + 224
> 35  QtWidgets                           0x0000000105864594
> _ZN19QApplicationPrivate13notify_helperEP7QObjectP6QEvent + 272
> 36  QtWidgets                           0x00000001058665c0
> _ZN12QApplication6notifyEP7QObjectP6QEvent + 5072
> 37  QtWidgets.abi3.so                   0x0000000106a5b224
> _ZN15sipQApplication6notifyEP7QObjectP6QEvent + 248
> 38  QtCore                              0x0000000106f89474
> _ZN16QCoreApplication15notifyInternal2EP7QObjectP6QEvent + 292
> 39  QtWidgets                           0x0000000105864b34
> _ZN19QApplicationPrivate14sendMouseEventEP7QWidgetP11QMouseEventS1_S1_PS1_R8QPointerIS0_Ebb
>  + 808
> 40  QtWidgets                           0x00000001058c2860
> _ZNK21QWidgetRepaintManager3rhiEv + 11080
> 41  QtWidgets                           0x00000001058c1a6c
> _ZNK21QWidgetRepaintManager3rhiEv + 7508
> 42  QtWidgets                           0x0000000105864594
> _ZN19QApplicationPrivate13notify_helperEP7QObjectP6QEvent + 272
> 43  QtWidgets                           0x00000001058653e8
> _ZN12QApplication6notifyEP7QObjectP6QEvent + 504
> 44  QtWidgets.abi3.so                   0x0000000106a5b224
> _ZN15sipQApplication6notifyEP7QObjectP6QEvent + 248
> 45  QtCore                              0x0000000106f89474
> _ZN16QCoreApplication15notifyInternal2EP7QObjectP6QEvent + 292
> 46  QtGui                               0x00000001076eb9ec
> _ZN22QGuiApplicationPrivate17processMouseEventEPN29QWindowSystemInterfacePrivate10MouseEventE
>  + 1740
> 47  QtGui                               0x0000000107747674
> _ZN22QWindowSystemInterface22sendWindowSystemEventsE6QFlagsIN10QEventLoop17ProcessEventsFlagEE
>  + 408
> 48  libqcocoa.dylib                     0x0000000107567d74
> qt_plugin_instance + 58768
> 49  CoreFoundation                      0x0000000187ff7a4c
> __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 28
> 50  CoreFoundation                      0x0000000187ff79e0
> __CFRunLoopDoSource0 + 176
> 51  CoreFoundation                      0x0000000187ff7750
> __CFRunLoopDoSources0 + 244
> 52  CoreFoundation                      0x0000000187ff6340
> __CFRunLoopRun + 828
> 53  CoreFoundation                      0x0000000187ff59ac
> CFRunLoopRunSpecific + 608
> 54  HIToolbox                           0x00000001925a4448
> RunCurrentEventLoopInMode + 292
> 55  HIToolbox                           0x00000001925a40d8
> ReceiveNextEventCommon + 220
> 56  HIToolbox                           0x00000001925a3fdc
> _BlockUntilNextEventMatchingListInModeWithFilter + 76
> 57  AppKit                              0x000000018b7d28a4
> _DPSNextEvent + 660
> 58  AppKit                              0x000000018bfac980
> -[NSApplication(NSEventRouting)
> _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 716
> 59  AppKit                              0x000000018b7c5d50
> -[NSApplication run] + 476
> 60  libqcocoa.dylib                     0x00000001075658fc
> qt_plugin_instance + 49432
> 61  QtCore                              0x0000000106f93160
> _ZN10QEventLoop4execE6QFlagsINS_17ProcessEventsFlagEE + 540
> 62  QtCore                              0x0000000106f89b00
> _ZN16QCoreApplication4execEv + 112
> 63  QtWidgets.abi3.so                   0x0000000106b6439c
> _ZL22meth_QApplication_execP7_objectS0_ + 96
> 64  Python                              0x00000001062722ec
> cfunction_call + 108
> 65  Python                              0x0000000106203378
> _PyObject_MakeTpCall + 128
> 66  Python                              0x0000000106348a40
> _PyEval_EvalFrameDefault + 47144
> 67  Python                              0x000000010633cf00
> PyEval_EvalCode + 304
> 68  Python                              0x00000001063bd448 
> run_mod + 176
> 69  Python                              0x00000001063bc4d8
> pyrun_file + 148
> 70  Python                              0x00000001063bb43c
> _PyRun_SimpleFileObject + 304
> 71  Python                              0x00000001063bb0ac
> _PyRun_AnyFileObject + 248
> 72  Python                              0x00000001063e9330
> pymain_run_file_obj + 220
> 73  Python                              0x00000001063e9070
> pymain_run_file + 72
> 74  Python                              0x00000001063e89a8
> Py_RunMain + 1464
> 75  Python                              0x00000001063e8b48
> pymain_main + 36
> 76  Python
> libc++abi: terminating due to uncaught exception of type NSException
> zsh: abort      python3 demo.py
> bobshotwell@Bobs-Mac-Studio documents %
> 
> This is the same error, under the same comditions, as the error I
> encountered in my generator application.  Note that line 17 is
> essentially the same statement, but it is run during initialization.
> Line 17 works as expected.
> 
> I then issued the same ChatGPT 4.0 prompt changing only ‘Pyqt6' to
> ‘Tkinter'.  The resulting script worked as expected.
> 
> Any assistance you can provide will be greatly appreciated.  My
> Application Generator is dead in the water with this error.  I really
> don't want to switch to Tkinter.
> 
> Bob Shotwell

I got the same crash the first time I ran it but couldn't repeat it 
after that. It's hard to see how it would be a PyQt bug - much more 
likely to be Qt.

Phil


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic