如何在 QML 中设置离线 OSM 目录的正确路径(不使用 qrc )?

How to set proper path to offline OSM directory in QML ( not using qrc )?

我想在带有 .exe 的文件夹中包含带有图块 realTiles 的文件夹。

当然我可以添加文件夹到qrc,一切正常:

import QtQuick 2.10
import QtQuick.Window 2.11
import QtLocation 5.12
import QtPositioning 5.12
...
Map {
        id: map
        anchors.fill: parent
        activeMapType: map.supportedMapTypes[0]
        zoomLevel: 14
        plugin: Plugin {
            name: 'osm';
            PluginParameter {
                name: 'osm.mapping.offline.directory'
                value: ':/realTiles/'
            }
        }
    }

所以我将文件夹 realTiles 复制到 .exe 文件夹和 .exe 上面的文件夹。例如,我在这 2 个位置有文件夹 realTiles

C:/Users/tom/Desktop/app/build-OsmOffline-Desktop_Qt_5_15_1_MinGW_64_bit-Release/release/realTiles C:/Users/tom/Desktop/app/build-OsmOffline-Desktop_Qt_5_15_1_MinGW_64_bit-Release/realTiles

我尝试使用插件参数的值:

value: 'file:///' + applicationDirPath + '/../realTiles/'
value: 'file:///realTiles/'
value: 'file:/realTiles/'

还有很多其他的。我当然可以做错。什么是真正的解决方案?

编辑:

main.qml


import QtQuick 2.10
import QtQuick.Window 2.11
import QtLocation 5.12
import QtPositioning 5.12
Window {
    id: win
    objectName: "window"
    visible: true
    width: 512
    height: 512

    Map {
        id: map
        anchors.fill: parent
        activeMapType: map.supportedMapTypes[0]
        plugin: Plugin {
            name: 'osm';
            PluginParameter {
                name: 'osm.mapping.offline.directory'
                //value: ':/realTiles/'
                value: 'file:///' + applicationDirPath + '/../realTiles/'
            }
        }
    }
}

main.cpp

#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QStandardPaths>
#include <QQmlContext>
int main(int argc, char *argv[])
{
    QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    QGuiApplication app(argc, argv);

    QQmlApplicationEngine engine;
    engine.rootContext()->setContextProperty("applicationDirPath", QGuiApplication::applicationDirPath());
    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));

    return app.exec();
}

尽量给出完整路径

        PluginParameter {
            name: "osm.mapping.cache.directory"
            value: "C:/Users/UserName/Desktop/OSMCache"
        }

我试过更改它起作用的缓存目录。因此请在值字段中提供完整路径。