Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to correctly pass property to PluginParameter value from C++ code?

How to correctly pass property to PluginParameter value from C++ code?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
qtlocationpluginosm
4 Posts 2 Posters 2.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    someoneinthebox
    wrote on 6 Jul 2017, 10:44 last edited by someoneinthebox 7 Jun 2017, 10:45
    #1

    Hello everyone!

    I've got the problem with passing property value through C++ to QML. My project is desktop application that must works with maps under Windows. So, after reading docs I found the best solution via QML using Qt Location. I chose OSM Plugin.

    I am using Qt 5.8

    Everything works good but I need to manually locate cache into custom directory. So for that I want to pass such property (cachePath) value from C++ code to QML.

    Part of C++ code:

    QQuickView *view = new QQuickView;
    view->rootContext()->setContextProperty("cachePath", "C:/111/");
    view->setSource(QUrl(QStringLiteral("qrc:/qml/OSMView.qml")));
    

    Important part of QML code:

    Map
    {
        zoomLevel: 10
    
        plugin: Plugin
        {
            name: "osm"
            PluginParameter { name: "osm.mapping.highdpi_tiles"; value: true }
            PluginParameter { name: "osm.mapping.offline.directory"; value: cachePath }
            PluginParameter { name: "osm.mapping.cache.directory"; value: cachePath }
        }
    
        <... nevermind ...>
    }
    

    So debug said that everything alright and property is passed. But there is no new tiles after work with maps in this custom directory.

    But, if I type manually value: "C:/111/" - everything works fine and directory is replenished with new cache tiles.

    What could be the problem?

    Thanks for advance!

    Mom said I am special.

    J 1 Reply Last reply 7 Jul 2017, 12:59
    0
    • S someoneinthebox
      6 Jul 2017, 10:44

      Hello everyone!

      I've got the problem with passing property value through C++ to QML. My project is desktop application that must works with maps under Windows. So, after reading docs I found the best solution via QML using Qt Location. I chose OSM Plugin.

      I am using Qt 5.8

      Everything works good but I need to manually locate cache into custom directory. So for that I want to pass such property (cachePath) value from C++ code to QML.

      Part of C++ code:

      QQuickView *view = new QQuickView;
      view->rootContext()->setContextProperty("cachePath", "C:/111/");
      view->setSource(QUrl(QStringLiteral("qrc:/qml/OSMView.qml")));
      

      Important part of QML code:

      Map
      {
          zoomLevel: 10
      
          plugin: Plugin
          {
              name: "osm"
              PluginParameter { name: "osm.mapping.highdpi_tiles"; value: true }
              PluginParameter { name: "osm.mapping.offline.directory"; value: cachePath }
              PluginParameter { name: "osm.mapping.cache.directory"; value: cachePath }
          }
      
          <... nevermind ...>
      }
      

      So debug said that everything alright and property is passed. But there is no new tiles after work with maps in this custom directory.

      But, if I type manually value: "C:/111/" - everything works fine and directory is replenished with new cache tiles.

      What could be the problem?

      Thanks for advance!

      J Offline
      J Offline
      Julien B
      wrote on 7 Jul 2017, 12:59 last edited by
      #2

      Hello @someoneinthebox,

      What the code below provide you?

      Component.onCompleted: {
          console.log("cachePath: " + cachePath)
      }
      
      S 1 Reply Last reply 7 Jul 2017, 14:29
      0
      • J Julien B
        7 Jul 2017, 12:59

        Hello @someoneinthebox,

        What the code below provide you?

        Component.onCompleted: {
            console.log("cachePath: " + cachePath)
        }
        
        S Offline
        S Offline
        someoneinthebox
        wrote on 7 Jul 2017, 14:29 last edited by someoneinthebox 7 Jul 2017, 14:29
        #3

        @Julien-B path that I passed of course. And thats why this is strange QML behavior I guess.

        Mom said I am special.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          someoneinthebox
          wrote on 14 Jul 2017, 12:18 last edited by
          #4

          If someone interesting you can solve problem like this:

          C++ side:

          QVariantMap params
          {
              {"osm.mapping.highdpi_tiles", YOUR_CUSTOM_VALUE},
              {"osm.mapping.offline.directory", YOUR_CUSTOM_VALUE},
              {"osm.mapping.cache.directory", YOUR_CUSTOM_VALUE}
          };
          
          QQuickView *view = new QQuickView;
          view->setSource(QUrl(QStringLiteral("qrc:/qml/OSMView.qml")));
          QObject *item = (QObject *) view->rootObject();
          QMetaObject::invokeMethod(item, "initializePlugin", Q_ARG(QVariant, QVariant::fromValue(params)));
          

          QML side:

          Item
          {
              id: osmMain    
              property variant parameters
          
              function initializePlugin(pluginParameters)
              {
                  var parameters = new Array;
                  for(var prop in pluginParameters)
                  {
                      var parameter = Qt.createQmlObject('import QtLocation 5.6; PluginParameter{ name: "'+ prop + '"; value: "' + pluginParameters[prop] + '"}', map)
                      parameters.push(parameter)
                  }
                  osmMain.parameters = parameters
                  map.plugin = Qt.createQmlObject('import QtLocation 5.6; Plugin{ name: "osm"; parameters: osmMain.parameters }', osmMain)
              }
          
              Map { id: map <...> }
          
          <...>
          
          }
          

          Mom said I am special.

          1 Reply Last reply
          0

          2/4

          7 Jul 2017, 12:59

          • Login

          • Login or register to search.
          2 out of 4
          • First post
            2/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved