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. Can't set MapPolyline path from C++
Forum Updated to NodeBB v4.3 + New Features

Can't set MapPolyline path from C++

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 496 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.
  • R Offline
    R Offline
    rykomick
    wrote on last edited by
    #1

    Hello, I'm trying to set a geopath for a QML MapPolyline in a QML map from C++. No matter what I try: it does not show the path. I'm trying to use QMetaObject::invokeMethod or setProperty method:

    QQuickWidget mapWidget(QUrl("qrc:/main.qml"));
    QObject *trackPolyObject = mapWidget.rootObject()->findChild<QObject*>("trackPolyLine");
    if(trackPolyObject)
    {
        int retVal;
        QMetaObject::invokeMethod(trackPolyObject, "setPath", Qt::DirectConnection,
                                  Q_RETURN_ARG(int, retVal), Q_ARG( QGeoPath, trackpointsmodel.currentGeoPath()));
    
        //bool ret = trackPolyObject->setProperty("path", trackpointsmodel.path());
    
        qDebug() << retVal;
    }
    

    QML side:

            MapPolyline {
                id: trackPolyLine
                objectName: "trackPolyLine"
                line.width: 4
                line.color: "darkBlue"
                antialiasing: true
            }
    

    The "trackpointsmodel" returns valid data in my application.
    Any hint? The QML part works and shows the route when I set the path property with some data in QML.

    1 Reply Last reply
    0
    • R Offline
      R Offline
      rykomick
      wrote on last edited by
      #2

      Found the cause of the problem: The doc of the MapPolyline QML class has an error. The "setPath" method has "void" return type and NOT int as described in the documentation. Thus the invoke methid call should look like this:

      QMetaObject::invokeMethod(trackPolyObject, "setPath", Q_ARG( QGeoPath, path));

      1 Reply Last reply
      0
      • eyllanescE Offline
        eyllanescE Offline
        eyllanesc
        wrote on last edited by
        #3

        @rykomick It is not recommended that you access QML objects directly from C++, it is best to create a QObject that has a property of the same type that the method requires and export it to QML through setContextProperty() or another mechanism and make the connection in QML.

        If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

        1 Reply Last reply
        0

        • Login

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