Forums

OverviewV-Play 2 Support (Qt 5) › How to integrate Vplay with Heartlistener demo?

Tagged: 

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

    Per

    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?

    #11564

    Günther
    V-Play Team

    Hi Per!

    There are two approaches to this. Either you add V-Play to the heartlistener example and correctly run it, or you start with an empty V-Play 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 V-Play 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 V-Play project:
    – Simply copy the heartrate C++ files (deviceinfo.h, deviceinfo.cpp, heartrate.h, heartrate.cpp) to your V-Play 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 V-Play, 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 V-Play application is available through the engine object. Setting the context property then works the same way.

    int main(int argc, char *argv[])
    {
        // other code
        vplay.initialize(&engine); 
        
        // 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 V-Play 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?

    Best,
    Günther

     

     

     

    • This reply was modified 3 years 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.

Voted #1 for:

  • Easiest to learn
  • Most time saving
  • Best support

Develop Cross-Platform Apps and Games 50% Faster!

  • Voted the best supported, most time-saving and easiest to learn cross-platform development tool
  • Based on the Qt framework, with native performance and appearance on all platforms including iOS and Android
  • Offers a variety of plugins to monetize, analyze and engage users
FREE!
create apps
create games
cross platform
native performance
3rd party services
game network
multiplayer
level editor
easiest to learn
biggest time saving
best support