Learn what Felgo offers to help your business succeed. Start your free evaluation today! Felgo for Your Business


OverviewFelgo 3 Support (Qt 5) › How to integrate Vplay with Heartlistener demo?


Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • #11365


    I can successfully register custom QML in Vplay main.cpp, but I cannot figure out how to combine CPP source with Vplay wizard-generated main.cpp. Specifically I want to add Vplay QML components to the Qt heartlistener demo, but the heartlistener main.cpp uses hooks that Vplay appears to remove (and I find no docs on the new Vplay methods like setMainQmlFileName).

    The Qt heartlistener main.cpp is at http://doc.qt.io/qt-5/qtbluetooth-heartlistener-assets-main-qml.html

    How do I modify this to use the Vplay main.cpp?


    Felgo Team

    Hi Per!

    There are two approaches to this. Either you add Felgo to the heartlistener example and correctly run it, or you start with an empty Felgo project and add the C++ features of the heartlistener example. I recommend to use the second approach, as it is easier to start with a correctly configured Felgo project.

    Essentially, it comes down to:
    – Adding all the C++ files and necessary includes to the project.
    – Setting a context property in the main.cpp to be able to access the C++ heartrate object.

    This are the steps to integrate the heartrate C++ features to a Felgo project:
    – Simply copy the heartrate C++ files (deviceinfo.h, deviceinfo.cpp, heartrate.h, heartrate.cpp) to your Felgo project. You can also create a folder “cpp” if you like.
    – In Qt Creator, right click the project and select “Add existing Files …”. Choose the C++ files you copied before.
    – You should now see the C++ Header and Source Files in the project tree. You can also have a look at the *.pro file. Adding the Headers and Sources essentially only created entries for the HEADERS and SOURCES configuration.
    – The heartrate C++ files use the Qt bluetooth features, so QT += bluetooth is also required in the *.pro file. You can also have a look at the heartlistener.pro configuration to see which packages and sources are included.
    – Now you are able to use the C++ files with the bluetooth features. By having a look at the heartrate-main.cpp, you can see that except setting up the application and the main qml source file, only one additional thing happens. A HeartRate object is created and added to the rootContext as a context property.
    – To do this in Felgo, we start by adding the required includes:

    #include <QQmlContext>
    #include "cpp/heartrate.h" // path to the heartrate.h you copied before

    – The rootContext of the Felgo application is available through the engine object. Setting the context property then works the same way.

    int main(int argc, char *argv[])
        // other code
        // add the heartrate context property
        HeartRate heartRate;
        engine.rootContext()->setContextProperty("heartRate", &heartRate);
        // other code
        return app.exec();

    Now you should be able to use the “heartRate” object through the context property within your Felgo application, in the same way as it is used by the heartrate example. E.g. heartRate.deviceSearch(), heartRate.message, …

    Hope this clears everything up a bit?





    • This reply was modified 8 years, 6 months ago by  GT.
Viewing 2 posts - 1 through 2 (of 2 total)

RSS feed for this thread

You must be logged in to reply to this topic.

Qt_Technology_Partner_RGB_475 Qt_Service_Partner_RGB_475_padded