20 for (
const PreloadEntry &entry : preload) {
22 obj[
"source"] = entry.source;
23 obj[
"destination"] = entry.destination;
24 jsonArray.append(obj);
26 QJsonDocument doc(jsonArray);
28 QFile outFile(destFile);
29 if (outFile.exists()) {
30 if (!outFile.remove()) {
31 std::cout <<
"ERROR: Failed to delete old file: " << outFile.fileName().toStdString()
36 if (!outFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
37 std::cout <<
"ERROR: Failed to open file for writing:" << outFile.fileName().toStdString()
41 if (outFile.write(doc.toJson(QJsonDocument::Indented)) == -1) {
42 std::cout <<
"ERROR: Failed writing into file :" << outFile.fileName().toStdString()
46 if (!outFile.flush()) {
47 std::cout <<
"ERROR: Failed flushing the file :" << outFile.fileName().toStdString()
57 QString qtLibPath =
"$QTDIR/lib";
58 QString qtQmlPath =
"$QTDIR/qml";
59 QString qtDeployQmlPath =
"/qt/qml";
60 QSet<PreloadEntry> res;
66 QJsonParseError parseError;
67 QJsonDocument doc = QJsonDocument::fromJson(output.toUtf8(), &parseError);
69 if (parseError.error != QJsonParseError::NoError) {
70 std::cout <<
"ERROR: QmlImport JSON parse error: " << parseError.errorString().toStdString()
75 std::cout <<
"ERROR: QmlImport JSON is not an array." <<
std::endl;
79 QJsonArray jsonArray = doc.array();
80 for (
const QJsonValue &value : jsonArray) {
81 if (value.isObject()) {
82 QJsonObject obj = value.toObject();
83 auto relativePath = obj[
"relativePath"].toString();
84 auto plugin = obj[
"plugin"].toString();
85 if (plugin.isEmpty() || relativePath.isEmpty()) {
88 auto pluginFilename =
"lib" + plugin +
".so";
89 addImport(PreloadEntry{
90 QDir::cleanPath(qtQmlPath +
"/" + relativePath +
"/" + pluginFilename),
91 QDir::cleanPath(qtDeployQmlPath +
"/" + relativePath +
"/" + pluginFilename) });
92 addImport(PreloadEntry{
93 QDir::cleanPath(qtQmlPath +
"/" + relativePath +
"/" +
"qmldir"),
94 QDir::cleanPath(qtDeployQmlPath +
"/" + relativePath +
"/" +
"qmldir") });