【问题标题】:What is triggering "ASSERT failure in QCoreApplication::sendEvent" here?什么在此处触发“QCoreApplication::sendEvent 中的 ASSERT 失败”?
【发布时间】: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


    【解决方案1】:

    我想通了。

    错误消息非常具有误导性,因为问题是虚拟的 QEventLoop。

    当主窗口(gw2g)QPushButton被点击时,它会退出这个事件循环,那么为什么接收者(gw2g)呢?


    所以,我刚刚摆脱了

    wait_xcon.exec(); 
    

    并用一个简单的替换它

    while(!quitloop){}
    

    现在单击按钮会将此布尔值设置为 true

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-04-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-23
      • 1970-01-01
      • 1970-01-01
      • 2010-12-07
      • 1970-01-01
      相关资源
      最近更新 更多