问题:
qt报错“QCoreApplication::sendEvent: "cannot send events to objects owned by a different thread”
QSocketNotifier: Socket notifiers cannot be enabled or disabled from another thread
...
ASSERT failure in QCoreApplication::sendEvent: "Cannot send events to objects owned by a different thread. Current thread 0x0x4ffc44. Receiver '' (of type 'QNativeSocketEngine') was created in thread 0x0x5bb358", file kernel\qcoreapplication.cpp, line 563
Debug Error!
原因:
socketPtr->close(); 这句报错,因为是在主线程里创建socket并打开,但是在另一个线程里关闭,就会报错。
解决方案:
不直接在另一个线程里关闭socket,而是通过发信号的方式,通知socket所在线程关闭socket。