我试图在 Qt 5.1 和 MSVC 2010 中使用 std::bind 将 QNetworkReply 事件挂钩到成员函数,同时将回复作为参数传递。直接将 std::bind 放在连接行中失败,在 MSVC 2010 上出现大量模板错误,但使用 std::function 将其分为两行。我很想坚持一条线。使这一切发生的魔法咒语是什么?
void MyClass::doRequest ( )
{
..
QNetworkReply * reply = nam.get(...)
// next line fails on MSVC 2010
connect(reply, &QNetworkReply::finished, std::bind(&MyClass::onNetworkDone, this, reply));
// next two lines do work on MSVC 2010
std::function<void ()> a = std::bind<void()>(&MyClass::onNetworkDone, this, reply);
connect(reply, &QNetworkReply::finished, a);
}
void MyClass::onNetworkDone( QNetworkReply * reply )
{
..
}