【发布时间】:2019-11-08 16:07:20
【问题描述】:
我有这两个信号:
void dataSampled(size_t a);
void error(const QString& message);
其他地方:
m_acquisitionThread = new QThread(this);
m_acquisitionManager = new AcquisitionManager();
QObject::connect(m_acquisitionManager, &AcquisitionManager::dataSampled,
this, &Application::onDataSampled); // this Application pointer
QObject::connect(m_acquisitionManager, &AcquisitionManager::error,
this, &Application::showError); // this Application pointer
m_acquisitionManager->moveToThread(m_acquisitionThread);
m_acquisitionThread->start();
AcquisitionManager 是一个移动到线程的对象,应用程序位于“主”线程中。
当我向应用程序发送信号时,连接到 dataSampled 的需要 size_t 的插槽不会执行,将 size_t 更改为 int(仅信号,插槽可以保持 size_t)甚至删除它可以解决问题。这真的很奇怪,有人知道为什么没有发送信号吗?在另一个应用程序(但单线程)中,我测试了 size_t 从信号发送到插槽没有问题(但上下文再次不同)。
void AcquisitionManager::executeDataAcquisition()
{
emit dataSampled(666); // onDataSampled is never executed (only if I change signal type from size_t to an int or something else)
emit error("foobar"); // Application::showError is always executed !
【问题讨论】:
-
你试过用 Qt::QueuedConnection 连接吗?这应该会处理好它,而不必将其注册为元类型。
标签: qt