【发布时间】:2016-02-18 23:10:48
【问题描述】:
我正在尝试编写一个将其参数传递给QObject::connect 的函数。
template <typename Func1, typename Func2>
void addConnection(const QObject* sender, Func1 signal, Func2 slot)
{
m_connections.push_back(QObject::connect(sender, signal, slot));
}
我是这样称呼它的:
addConnection(&m_scannerSystem, &ScannerSystem::signalStatus, [=](int status){ this->onStatusChanged(status); });
这会导致错误:
'QObject::connect' : none of the 4 overloads could convert all the argument types
但我无法弄清楚为什么它不起作用。
【问题讨论】:
-
为什么要传值?
-
@deW1 我正在传递函数指针,为什么不按值传递它们? QObject::connect 具有相同的签名。
标签: c++ qt templates lambda signals-slots