diff -r 9e0dfa78f349 -r 30a34d639e90 src/EditRecipe.cpp --- a/src/EditRecipe.cpp Wed Apr 06 21:41:58 2022 +0200 +++ b/src/EditRecipe.cpp Wed Apr 06 21:57:02 2022 +0200 @@ -196,9 +196,34 @@ const auto& h_json = query.value(85).toString(); if (!h_json.trimmed().isEmpty()) { const auto& formattedJson = QString("%1").arg(h_json); - this->hops = QJsonDocument::fromJson(formattedJson.toUtf8(), &parseError); - if (parseError.error != QJsonParseError::NoError) - qDebug() << "Parse error: " << parseError.errorString() << "at" << parseError.offset ; + QJsonDocument hops = QJsonDocument::fromJson(formattedJson.toUtf8(), &parseError); + if (parseError.error != QJsonParseError::NoError) { + qDebug() << "Parse error: " << parseError.errorString() << "at" << parseError.offset; + } else if (hops.isArray()) { + for (int i = 0; i < hops.array().size(); i++) { + QJsonObject obj = hops.array().at(i).toObject(); + qDebug() << i << obj; + Hops h; + h.h_name = obj["h_name"].toString(); + h.h_origin = obj["h_origin"].toString(); + h.h_amount = obj["h_amount"].toDouble(); + h.h_cost = obj["h_cost"].toDouble(); + h.h_type = obj["h_type"].toInt(); + h.h_form = obj["h_form"].toInt(); + h.h_useat = obj["h_useat"].toInt(); + h.h_time = obj["h_time"].toInt(); + h.h_alpha = obj["h_alpha"].toDouble(); + h.h_beta = obj["h_beta"].toDouble(); + h.h_hsi = obj["h_hsi"].toDouble(); + h.h_humulene = obj["h_humulene"].toDouble(); + h.h_caryophyllene = obj["h_caryophyllene"].toDouble(); + h.h_cohumulone = obj["h_cohumulone"].toDouble(); + h.h_myrcene = obj["h_myrcene"].toDouble(); + h.h_total_oil = obj["h_total_oil"].toDouble(); + recipe->hops.append(h); + } + qDebug() << "hops" << recipe->hops.size(); + } } else { qDebug() << "empty hops"; } @@ -371,9 +396,6 @@ recipe->wa_acid_name = 0; recipe->wa_acid_perc = 80; recipe->wa_base_name = 0; - - const auto& formattedJson = QString("[]"); - this->hops = QJsonDocument::fromJson(formattedJson.toUtf8()); } ui->lockedEdit->setChecked(recipe->locked);