我連接的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時獲得排隊連接?
我認爲這將是一個騙局,因爲對目標上下文的要求確實使它有點不直觀,但顯然不是。 –