【发布时间】:2020-11-20 03:07:49
【问题描述】:
我收到此错误: QCoreApplication::sendEvent 中的 ASSERT 失败:“无法将事件发送到其他线程拥有的对象。当前线程 0x0x20e51b65eb0。接收器 'gw2g'(来自type 'gw2g') 是在线程 0x0x20e4fd0c930"中创建的"
调试:
MAIN_thread 启动:QThread(0x20e4fd0c930)
DUMMY_LOOP 开始:QThread(0x20e51b65eb0)
什么可能导致此错误?
gw2g.cpp
addExtenders()
{
//...model gets set etc
//
connect(this, SIGNAL(xprep_ready(bool)), ui->connectButton, SLOT(setEnabled(bool)), Qt::AutoConnection);
connect(ui->listView->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), this, SLOT(prep_connectx(QItemSelection)), Qt::AutoConnection);
}
在使用断点进行调试时,我发现在离开 addExtenders() 后出现此错误
我还在 dummyMain_c 和 gw2g 的析构函数中设置了断点,它们都不会被意外破坏。 有时 dummyMain_c 确实会被意外破坏。
(按重试调试应用程序) QCoreApplication::exec: 事件循环已经在运行
可能和这个event_loop有关
emit extend_list();
wait_xcon.exec();
单击 GUI 中的某个按钮时会退出。
QObject::connect(mwindow.ui->connectButton, &QPushButton::clicked, &dummy_main.wait_xcon, &QEventLoop::quit);
不幸的是,我什至没有进入那部分。
图中的线程是主线程(0x0x2059fdfd9b0)和虚拟线程(0x0x205a1c85ff0)
我还检查了是否所有主窗口函数都在主线程中运行 - 确实如此。 所以所有 GUI 的东西都发生在主要的地方——我不知道了。
【问题讨论】:
标签: c++ multithreading qt assert signals-slots