我连接的lambda到QObject
的信号:如何在连接lambda时将Qt :: ConnectionType传递给QObject :: connect?
QObject::connect(handle, &BatchHandle::progressMax, [this](const ProcessHandle* const self, const int value) {
this->maxProgress(value);
});
上面的代码没有问题编译。
但是,因为handle
对象最终会移动到另一个线程,所以Qt::QueuedConnection
是绝对必要的。
我将此添加到我的代码:
QObject::connect(handle, &BatchHandle::finished, [this](const ProcessHandle* const self) {
this->processIsRunning(false);
}, (Qt::ConnectionType)Qt::QueuedConnection);
注意我是如何加入明确的转换,以确保它正确标识值类型。结果:
1>src\TechAdminServices\database\techCore\processes\import\ImportManagerDialog.cpp(191): error C2664: 'QMetaObject::Connection QObject::connect<void(__cdecl taservices::ProcessHandle::*)(const taservices::ProcessHandle *),Qt::ConnectionType>(const taservices::ProcessHandle *,Func1,const QObject *,Func2,Qt::ConnectionType)' : cannot convert parameter 3 from 'taservices::`anonymous-namespace'::<lambda58>' to 'const QObject *'
1> with
1> [
1> Func1=void (__cdecl taservices::ProcessHandle::*)(const taservices::ProcessHandle *),
1> Func2=Qt::ConnectionType
1> ]
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
如何在连接lambda时获得排队连接?
我认为这将是一个骗局,因为对目标上下文的要求确实使它有点不直观,但显然不是。 –