报错:
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] + 352
1 AppKit 0x00007fff22bbb121 -[NSWindow _initContent:styleMask:backing:defer:contentView:] + 1375
2 AppKit 0x00007fff22d7d377 -[NSPanel _initContent:styleMask:backing:defer:contentView:] + 50
3 AppKit 0x00007fff22bbabbb -[NSWindow initWithContentRect:styleMask:backing:defer:] + 42
4 AppKit 0x00007fff22d7d32c -[NSPanel initWithContentRect:styleMask:backing:defer:] + 64
5 AppKit 0x00007fff22ec51f4 -[NSWindow initWithContentRect:styleMask:backing:defer:screen:] + 52
6 libqcocoa.dylib 0x0000000136c61745 -[QNSPanel initWithContentRect:styleMask:backing:defer:screen:platformWindow:] + 197
7 libqcocoa.dylib 0x0000000136c4dcac _ZN12QCocoaWindow14createNSWindowEb + 1324
8 libqcocoa.dylib 0x0000000136c47672 _ZN12QCocoaWindow22recreateWindowIfNeededEv + 1266
9 libqcocoa.dylib 0x0000000136c470fe _ZN12QCocoaWindow10initializeEv + 318
10 QtGui 0x000000010abb7eb7 _ZN14QWindowPrivate6createEby + 151
11 QtWidgets 0x0000000109cfc771 _ZN14QWidgetPrivate6createEv + 1185
12 QtWidgets 0x0000000109cfb414 _ZN7QWidget6createEybb + 324
13 QtWidgets 0x0000000109d0e81d _ZN14QWidgetPrivate10setVisibleEb + 189
14 QtWidgets 0x0000000109ed557d _ZN7QDialog10setVisibleEb + 269
15 QtWidgets 0x0000000109ed4d80 _ZN7QDialog4execEv + 240
16 QtWidgets 0x0000000109f12a72 _ZL17showNewMessageBoxP7QWidgetN11QMessageBox4IconERK7QStringS5_6QFlagsINS1_14StandardButtonEES7_ + 354
17 QtWidgets.abi3.so 0x00000001091f0c4b _ZL24meth_QMessageBox_warningP7_objectS0_S0_ + 235
18 Python 0x00000001089af1bd _PyMethodDef_RawFastCallKeywords + 685
19 Python 0x00000001089ae5ba _PyCFunction_FastCallKeywords + 42
20 Python 0x0000000108a6d804 call_function + 724
21 Python 0x0000000108a6a7dd _PyEval_EvalFrameDefault + 25181
22 Python 0x00000001089ae9f0 function_code_fastcall + 128
23 Python 0x00000001089adfe4 _PyFunction_FastCallDict + 148
24 Python 0x00000001089af49f _PyObject_Call_Prepend + 143
25 Python 0x00000001089ae6e7 PyObject_Call + 135
26 Python 0x0000000108a6aaee _PyEval_EvalFrameDefault + 25966
27 Python 0x00000001089ae9f0 function_code_fastcall + 128
28 Python 0x0000000108a6d812 call_function + 738
29 Python 0x0000000108a6a7c3 _PyEval_EvalFrameDefault + 25155
30 Python 0x00000001089ae9f0 function_code_fastcall + 128
31 Python 0x0000000108a6d812 call_function + 738
32 Python 0x0000000108a6a7c3 _PyEval_EvalFrameDefault + 25155
33 Python 0x00000001089ae9f0 function_code_fastcall + 128
34 Python 0x00000001089adfe4 _PyFunction_FastCallDict + 148
35 Python 0x00000001089af49f _PyObject_Call_Prepend + 143
36 Python 0x00000001089ae6e7 PyObject_Call + 135
37 Python 0x0000000108af5b47 t_bootstrap + 71
38 Python 0x0000000108aac899 pythread_wrapper + 25
39 libsystem_pthread.dylib 0x00007fff2035a950 _pthread_start + 224
40 libsystem_pthread.dylib 0x00007fff2035647b thread_start + 15
)
原因
在使用pyqt的时候,我使用threading创建了一个线程然后在里面处理数据,处理的时候检测异常然后用qmessagebox提示错误信息时报错上面内容。
原因很简单不能在线程的函数里面使用qmessagebox