| 332 | } |
| 333 | |
| 334 | bool 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 | |
| 369 | bool CDatabase::ImportFromJsonFile(const QString &szFile) |
| 370 | { |
no test coverage detected