当前位置: 代码迷 >> 综合 >> QObject::setParent: Cannot set parent, new parent is in a different thread 2021-03-27 19:58:38.354 P
  详细解决方案

QObject::setParent: Cannot set parent, new parent is in a different thread 2021-03-27 19:58:38.354 P

热度:50   发布时间:2023-11-21 13:29:22.0

报错:

QObject::setParent: Cannot set parent, new parent is in a different thread
2021-03-27 19:58:38.354 Python[1331:38623] WARNING: NSWindow drag regions should only be invalidated on the Main Thread! This will throw an exception in the future. Called from (0   AppKit                              0x00007fff22bd047f -[NSWindow(NSWindow_Theme) _postWindowNeedsToResetDragMarginsUnlessPostingDisabled] + 3521   AppKit                              0x00007fff22bbb121 -[NSWindow _initContent:styleMask:backing:defer:contentView:] + 13752   AppKit                              0x00007fff22d7d377 -[NSPanel _initContent:styleMask:backing:defer:contentView:] + 503   AppKit                              0x00007fff22bbabbb -[NSWindow initWithContentRect:styleMask:backing:defer:] + 424   AppKit                              0x00007fff22d7d32c -[NSPanel initWithContentRect:styleMask:backing:defer:] + 645   AppKit                              0x00007fff22ec51f4 -[NSWindow initWithContentRect:styleMask:backing:defer:screen:] + 526   libqcocoa.dylib                     0x0000000136c61745 -[QNSPanel initWithContentRect:styleMask:backing:defer:screen:platformWindow:] + 1977   libqcocoa.dylib                     0x0000000136c4dcac _ZN12QCocoaWindow14createNSWindowEb + 13248   libqcocoa.dylib                     0x0000000136c47672 _ZN12QCocoaWindow22recreateWindowIfNeededEv + 12669   libqcocoa.dylib                     0x0000000136c470fe _ZN12QCocoaWindow10initializeEv + 31810  QtGui                               0x000000010abb7eb7 _ZN14QWindowPrivate6createEby + 15111  QtWidgets                           0x0000000109cfc771 _ZN14QWidgetPrivate6createEv + 118512  QtWidgets                           0x0000000109cfb414 _ZN7QWidget6createEybb + 32413  QtWidgets                           0x0000000109d0e81d _ZN14QWidgetPrivate10setVisibleEb + 18914  QtWidgets                           0x0000000109ed557d _ZN7QDialog10setVisibleEb + 26915  QtWidgets                           0x0000000109ed4d80 _ZN7QDialog4execEv + 24016  QtWidgets                           0x0000000109f12a72 _ZL17showNewMessageBoxP7QWidgetN11QMessageBox4IconERK7QStringS5_6QFlagsINS1_14StandardButtonEES7_ + 35417  QtWidgets.abi3.so                   0x00000001091f0c4b _ZL24meth_QMessageBox_warningP7_objectS0_S0_ + 23518  Python                              0x00000001089af1bd _PyMethodDef_RawFastCallKeywords + 68519  Python                              0x00000001089ae5ba _PyCFunction_FastCallKeywords + 4220  Python                              0x0000000108a6d804 call_function + 72421  Python                              0x0000000108a6a7dd _PyEval_EvalFrameDefault + 2518122  Python                              0x00000001089ae9f0 function_code_fastcall + 12823  Python                              0x00000001089adfe4 _PyFunction_FastCallDict + 14824  Python                              0x00000001089af49f _PyObject_Call_Prepend + 14325  Python                              0x00000001089ae6e7 PyObject_Call + 13526  Python                              0x0000000108a6aaee _PyEval_EvalFrameDefault + 2596627  Python                              0x00000001089ae9f0 function_code_fastcall + 12828  Python                              0x0000000108a6d812 call_function + 73829  Python                              0x0000000108a6a7c3 _PyEval_EvalFrameDefault + 2515530  Python                              0x00000001089ae9f0 function_code_fastcall + 12831  Python                              0x0000000108a6d812 call_function + 73832  Python                              0x0000000108a6a7c3 _PyEval_EvalFrameDefault + 2515533  Python                              0x00000001089ae9f0 function_code_fastcall + 12834  Python                              0x00000001089adfe4 _PyFunction_FastCallDict + 14835  Python                              0x00000001089af49f _PyObject_Call_Prepend + 14336  Python                              0x00000001089ae6e7 PyObject_Call + 13537  Python                              0x0000000108af5b47 t_bootstrap + 7138  Python                              0x0000000108aac899 pythread_wrapper + 2539  libsystem_pthread.dylib             0x00007fff2035a950 _pthread_start + 22440  libsystem_pthread.dylib             0x00007fff2035647b thread_start + 15
)

原因

在使用pyqt的时候,我使用threading创建了一个线程然后在里面处理数据,处理的时候检测异常然后用qmessagebox提示错误信息时报错上面内容。
原因很简单不能在线程的函数里面使用qmessagebox

  相关解决方案