title: Implementing callback in Qt
body: <p>I want to implement some kind of callback in Qt.</p>
  
  <p>I have a class called <strong>ApiHandler</strong> for making requests. And i should have a way to pass a function as callback to <strong>makeRequest</strong> and execute it when <strong>replyFinished</strong>.
  I know a way using <strong>std::function/std::bind</strong>. But maybe there are ways to do this using Qt? Slots? Or more detailed explanation about using <strong>std::function/std::bind</strong> in this case.</p>
  
  <p>Thanks!</p>
  
  <pre><code>typedef void (*callback)();
  void ApiHandler::makeRequest(QString method, QMap&lt;QString, QString&gt; parameters, callback)
  {
      QUrl url = this-&gt;buildCall(method, parameters);
  
      connect(this-&gt;manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*, callback)));
  
      QNetworkRequest request;
      request.setUrl(url);
      request.setRawHeader("User-Agent", "Test");
  
      QNetworkReply *reply = this-&gt;manager-&gt;get(request);
      connect(reply, SIGNAL(readyRead()), this, SLOT(slotReadyRead()));
      connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(slotError(QNetworkReply::NetworkError)));
      connect(reply, SIGNAL(sslErrors(QList&lt;QSslError&gt;)), this, SLOT(slotSslErrors(QList&lt;QSslError&gt;)));
  }
  void ApiHandler::replyFinished(QNetworkReply* reply, callback)
  {
      qDebug() &lt;&lt; "replyFinished" &lt;&lt; reply-&gt;url();
      QJsonDocument j = QJsonDocument::fromJson(reply-&gt;readAll());
      if (j.isEmpty()) {
          // throw error
      }
  
      // call the callback with "j" as parameter
      // callback(j)
  
      reply-&gt;deleteLater();
  }
  </code></pre>