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).
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
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 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?
Best,
Günther
This reply was modified 7 years, 7 months ago by GT.
By signing up, you consent to Felgo processing your data & contacting you to fulfill your request. For more information on how we are committed to protecting & respecting your privacy, please review our privacy policy.
Want to find out if Felgo is a good fit for your company?
As part of the free Business evaluation, we offer a free welcome call for companies, to talk about your requirements, and how the Felgo SDK & Services can help you. Just sign up and schedule your call.
Sign up now to start your free Business evaluation: