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

@ -82,7 +82,8 @@ QJsonArray File::get_decoders()
auto *data = rd.GetInnterFileData("decoders");
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();
QJsonDocument sessionDoc = QJsonDocument::fromJson(qbs, &error);
@ -108,7 +109,8 @@ QJsonDocument File::get_session()
auto *data = rd.GetInnterFileData("session");
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();
sessionDoc = QJsonDocument::fromJson(qbs, &error);

View File

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

View File

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

View File

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