Skip to content

Instantly share code, notes, and snippets.

@lbt
Last active August 29, 2015 14:05
Show Gist options
  • Save lbt/9d2f1c9933fed5922dfb to your computer and use it in GitHub Desktop.
Save lbt/9d2f1c9933fed5922dfb to your computer and use it in GitHub Desktop.
void SparkVariable::callFinished(QJsonDocument json) {
if (json.isNull()) goto cleanup;
if (! json.isObject()) { qDebug() << "expected a json object"; goto cleanup; }
QJsonObject jo = json.object();
if (jo.isEmpty()) { qDebug() << "json object is empty"; goto cleanup; }
QJsonValue return_value = jo["return_value "];
QVariant value = return_value.toVariant();
qDebug() << "a function from " << m_variable << " returned " << return_value;
emit result(value);
cleanup:
emit busyChanged(m_busy=false);
return;
}
// Using lambdas :
void SparkVariable::callFinished(QJsonDocument json) {
auto cleanup = [this] () {
emit busyChanged(m_busy = false);
};
if (json.isNull()) { cleanup(); return; }
if (! json.isObject()) { qDebug() << "expected a json object"; cleanup(); return; }
QJsonObject jo = json.object();
if (jo.isEmpty()) { qDebug() << "json object is empty"; cleanup(); return; }
QJsonValue return_value = jo["return_value "];
QVariant value = return_value.toVariant();
qDebug() << "a function from " << m_variable << " returned " << return_value;
emit result(value);
cleanup();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment