title: How to access QObject::sender in a C++ lambda?
body: <p>This is a rather unusual problem - but a problem nonetheless. I have a function that accepts a lambda as a parameter and then passes it on to <code>QObject::connect</code>:</p>
  
  <pre><code>template&lt;typename Functor&gt;
  void MyClass::doSomething(Functor f)
  {
      connect(network_reply, &amp;QNetworkReply::finished, f);
      //...
  }
  </code></pre>
  
  <p>A sample invocation of <code>MyClass::doSomething</code> might look like this:</p>
  
  <pre><code>doSomething([]()
  {
      // how do I get access to the sender???
  });
  </code></pre>
  
  <p>As you can tell by my comment, there is no way to access <code>QObject::sender</code> to get a pointer to the <code>QObject</code> that emitted the signal. Because the class emitting the signal is not in the scope that the lambda is being created in, there is no way of referencing it inside the lambda.</p>
  
  <p>What options do I have?</p>
  
  <hr>
  
  <p><strong>Edit:</strong> I tried using Andy's suggestion (<code>std::bind</code>) but I end up getting one of those template errors that are nearly impossible to understand:</p>
  
  <p><a href="http://paste.ubuntu.com/1614425/" rel="nofollow">http://paste.ubuntu.com/1614425/</a></p>
  
  <p>Excerpt:</p>
  
  <pre>decltype cannot resolve address of overloaded function</pre>
  
  <p>...and it points to the <code>QObject::connect</code> call.</p>