title: Disconnecting lambda functions in Qt5
body: <p>Is it possible to disconnect a lambda function? And if "yes", how?</p>
  
  <p>According to <a href="https://qt-project.org/wiki/New_Signal_Slot_Syntax" rel="noreferrer">https://qt-project.org/wiki/New_Signal_Slot_Syntax</a> I need to use a <code>QMetaObject::Connection</code> which is returned from the QObject::connect method, but then how can I pass that object to the lambda function?</p>
  
  <p>Pseudo-code example:</p>
  
  <pre><code>QMetaObject::Connection conn = QObject::connect(m_sock, &amp;QLocalSocket::readyRead, [this](){
      QObject::disconnect(conn); //&lt;---- Won't work because conn isn't captured
  
      //do some stuff with sock, like sock-&gt;readAll();
  }
  </code></pre>