Display GPS Route Data in a Widget



  • Hello,

    for my research project i made a gui in qt for displaying measurement data and image processing data with opencv. Since we are making the measurement with a moving vehicle, i need to display the driving route on to a map while we a measuring.

    Until now i tried QML Map (Qt Location and openstreetmap) within a QQuickWidget and it worked fine. I can also draw a line with MapPolyline. But i cant interact from my c++ classes to the QML to update the line/route.

    I now have some questions to the experts :)

    • Is my approach going to work? I though if the data handling between c++ and qml through the QQuickWidget does not work, it might be working if i write the data from c++ into a file and read the data in QML. But i have no idea how to read the data and display it the wright way.
    • Are other Methods like ArcGIS, KDE Marble etc better? I've tried those, but could not get them to work.

    Sorry if these are stupid questions but i am a mechanical engineer not a software developper and i am new to the Qt and especially to the QML Game :)


  • Moderators

    @UltraPG said in Display GPS Route Data in a Widget:

    Until now i tried QML Map (Qt Location and openstreetmap) within a QQuickWidget and it worked fine. I can also draw a line with MapPolyline. But i cant interact from my c++ classes to the QML to update the line/route.

    An advice: stay using Qt QML Maps! The mapping of the displayed area to the data in a custom widget can be a very horrific task, even more when you are not a "real" software developer.

    Of course you can interact with the data. Maybe not directly from within C++, but indirectly.
    Means for example: let your C++ code fire some signals and react to them inside your QML code, which then does the appropriate work.

    You may want to start reading here.



  • @UltraPG you may already have taken a look at this QML Map Viewer, but just in case.

    It looks very promising as it has several features, including directions and travel routes via RouteModel and MapRoute QML types. So it seems that most of the components you might need for your project are already available on QML and you may eventually interact with them from C++ as indicated in previous post.



  • Thanks for the help. I've managed it now to interact between C++ and QML. But i can't get to work the invokeMethod to start a function inside QML from C++ with the QQuickWidget.

    From the Link there is this example:

    QML:

    import QtQuick 2.0
    
    Item {
        function myQmlFunction(msg) {
            console.log("Got message:", msg)
            return "some return value"
        }
    }
    

    C++:

        QQuickWidget *quickWidget = new QQuickWidget();
        QQmlContext* context = quickWidget->rootContext();
    
        //Method to access properties between QML and C++
        context->setContextProperty("dataStore", &dt);
        quickWidget->setSource(QUrl(QStringLiteral("qrc:/main.qml")));
        quickWidget->show();
        ui->verticalLayout->addWidget(quickWidget);
        
        //Method to call a function from QML in C++
        QObject *obj = context->contextObject();
        QVariant returnedValue;
        QVariant msg = "Hello from C++";
        QMetaObject::invokeMethod(obj,"myQmlFunction",Q_RETURN_ARG(QVariant, returnedValue),Q_ARG(QVariant, msg));
    
        qDebug() << "QML function returned: " << returnedValue.toString();
    

    But the function inside QML won't be excecuted. How is the correct way to call a QML function from a QQuickWidget inside C++?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.