fix: can't resotre i2c decoder from data file

This commit is contained in:
dreamsourcelabTAI 2022-08-02 11:49:44 +08:00
parent 9264bce374
commit bb06d1cccd
4 changed files with 16 additions and 14 deletions

View File

@ -81,8 +81,9 @@ QJsonArray File::get_decoders()
ZipReader rd(f_name.c_str()); ZipReader rd(f_name.c_str());
auto *data = rd.GetInnterFileData("decoders"); auto *data = rd.GetInnterFileData("decoders");
if (data != NULL){ if (data != NULL){
QString jsonStr(data->data()); QByteArray raw_bytes = QByteArray::fromRawData(data->data(), data->size());
QString jsonStr(raw_bytes.data());
QByteArray qbs = jsonStr.toUtf8(); QByteArray qbs = jsonStr.toUtf8();
QJsonDocument sessionDoc = QJsonDocument::fromJson(qbs, &error); QJsonDocument sessionDoc = QJsonDocument::fromJson(qbs, &error);
@ -108,8 +109,9 @@ QJsonDocument File::get_session()
auto *data = rd.GetInnterFileData("session"); auto *data = rd.GetInnterFileData("session");
if (data != NULL){ if (data != NULL){
QString jsonStr(data->data()); QByteArray raw_bytes = QByteArray::fromRawData(data->data(), data->size());
QByteArray qbs = jsonStr.toUtf8(); QString jsonStr(raw_bytes.data());
QByteArray qbs = jsonStr.toUtf8();
sessionDoc = QJsonDocument::fromJson(qbs, &error); sessionDoc = QJsonDocument::fromJson(qbs, &error);
if (error.error != QJsonParseError::NoError){ if (error.error != QJsonParseError::NoError){

View File

@ -1266,8 +1266,7 @@ bool MainWindow::on_store_session(QString name)
QJsonObject sessionVar; QJsonObject sessionVar;
if (!gen_session_json(sessionVar)) if (!gen_session_json(sessionVar))
return false; return false;
QJsonDocument sessionDoc(sessionVar); QJsonDocument sessionDoc(sessionVar);
//sessionFile.write(QString::fromUtf8(sessionDoc.toJson()));
outStream << QString::fromUtf8(sessionDoc.toJson()); outStream << QString::fromUtf8(sessionDoc.toJson());
sessionFile.close(); sessionFile.close();
return true; return true;
@ -1280,7 +1279,7 @@ bool MainWindow::genSessionData(std::string &str)
return false; return false;
QJsonDocument sessionDoc(sessionVar); QJsonDocument sessionDoc(sessionVar);
QString data = QString::fromUtf8(sessionDoc.toJson()); QString data = QString::fromUtf8(sessionDoc.toJson());
str.append(data.toLatin1().data()); str.append(data.toLocal8Bit().data());
return true; return true;
} }

View File

@ -60,8 +60,8 @@
#include "dsvdef.h" #include "dsvdef.h"
#include "utility/encoding.h" #include "utility/encoding.h"
#include "utility/path.h" #include "utility/path.h"
#include "log.h" #include "log.h"
#include <QDebug>
namespace pv { namespace pv {
@ -875,8 +875,8 @@ bool StoreSession::decoders_gen(std::string &str)
if (!json_decoders(dec_array)) if (!json_decoders(dec_array))
return false; return false;
QJsonDocument sessionDoc(dec_array); QJsonDocument sessionDoc(dec_array);
QString data = QString::fromUtf8(sessionDoc.toJson()); QString data = QString::fromUtf8(sessionDoc.toJson());
str.append(data.toLatin1().data()); str = std::string(data.toLocal8Bit().data());
return true; return true;
} }
@ -952,7 +952,7 @@ bool StoreSession::json_decoders(QJsonArray &array)
auto rows = stack->get_rows_gshow(); auto rows = stack->get_rows_gshow();
for (auto i = rows.begin(); i != rows.end(); i++) { for (auto i = rows.begin(); i != rows.end(); i++) {
pv::data::decode::Row _row = (*i).first; pv::data::decode::Row _row = (*i).first;
QString kn(_row.title().toUtf8().data()); QString kn = _row.title();
show_obj[kn] = QJsonValue::fromVariant((*i).second); show_obj[kn] = QJsonValue::fromVariant((*i).second);
} }
dec_obj["show"] = show_obj; dec_obj["show"] = show_obj;

View File

@ -36,8 +36,9 @@ namespace encoding{
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
stream.setEncoding(QStringConverter::Utf8); stream.setEncoding(QStringConverter::Utf8);
#else #else
QTextCodec *code = QTextCodec::codecForName("UTF-8"); //QTextCodec *code = QTextCodec::codecForName("UTF-8");
stream.setCodec(code); // stream.setCodec(code);
stream.setCodec("UTF-8");
#endif #endif
} }
} }