MCPcopy Create free account
hub / github.com/KangLin/RabbitRemoteControl / ExportToJsonFile

Method ExportToJsonFile

Src/Database/Database.cpp:334–367  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

332}
333
334bool CDatabase::ExportToJsonFile(const QString &szFile)
335{
336 SetError();
337 QFile file(szFile);
338 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
339 SetError("Failed to open export JSON file: " + szFile + "; Error: " + file.errorString());
340 qCritical(log) << GetError();
341 return false;
342 }
343
344 QTextStream out(&file);
345#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
346 out.setEncoding(QStringConverter::Utf8);
347#else
348 out.setCodec("UTF-8");
349#endif
350 out.setGenerateByteOrderMark(true); // 添加 UTF-8 BOM
351
352 QJsonDocument doc;
353 QJsonObject root;
354 root.insert("Title", "Rabbit Remote Control");
355 root.insert("Author", "Kang Lin <kl222@126.com>");
356 root.insert("Version", "0.1.0");
357
358 bool bRet = true;
359 bRet = ExportToJson(root);
360 if(bRet) {
361 doc.setObject(root);
362 out << doc.toJson();
363 }
364
365 file.close();
366 return true;
367}
368
369bool CDatabase::ImportFromJsonFile(const QString &szFile)
370{

Callers 4

slotExportMethod · 0.80
slotExportMethod · 0.80
onExportBookmarksMethod · 0.80
exportToJsonMethod · 0.80

Calls 3

errorStringMethod · 0.80
openMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected