Quick Tip: Update QML on a live device in real-time! Featured

UI testing just got a great deal easier for Cascades developers! Developers can now make changes to their QML, and when the file is saved in the Momentics IDE, the changes are instantly seen on the currently paired test device. Want to use this? If so, follow along below.

 First, make sure you are using the latest IDE and using an API level of 10.2. Once that is verified, open the 'Window' menu and go to Window->Preferences > BlackBerry > check the "Send QML files to device on save" checkbox. Save your preferences.

Easy so far...

Next, you will need to add some code to your projects in which you want to use this new feature, so below is a quick way to make that happen.

In your project's 'src' directory create a new directory and name it 'support', and in that directory place the qmlbeam.cpp and qmlbeam.h files attached to the bottom of this post.

Once this is done, open your application cpp file (typically called applicationui.cpp) and add the following two lines (in bold)

#include "applicationui.hpp"
#include "support/qmlbeam.h"
#include <bb/cascades/Application> #include <bb/cascades/QmlDocument> #include <bb/cascades/AbstractPane> #include <bb/cascades/LocaleHandler> using namespace bb::cascades; ApplicationUI::ApplicationUI(bb::cascades::Application *app) : QObject(app) { // prepare the localization mTranslator = new QTranslator(this); mLocaleHandler = new LocaleHandler(this); bool res = QObject::connect(mLocaleHandler, SIGNAL(systemLanguageChanged()), this, SLOT(onSystemLanguageChanged())); // This is only available in Debug builds Q_ASSERT(res); // Since the variable is not used in the app, this is added to avoid a // compiler warning Q_UNUSED(res); // initial load onSystemLanguageChanged(); // Create scene document from main.qml asset, the parent is set // to ensure the document gets destroyed properly at shut down. QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this); // Create root object for the UI AbstractPane *root = qml->createRootObject<abstractpane>(); // Set created root object as the application scene app->setScene(root); // Add DevelopmentSupport, so that QML is reloaded on the fly. If a non-default // name of the main file asset is used the mainFile property can be set by calling // setMainFile() function on the qmlBeam object (responsible for beaming up the new QML).

new QmlBeam(this); }

Now, compile and deploy your project to your paired device, and you will see your QML changes occur in real time on your device each time you save a QML document!

Note: Thanks to BerryReview for pointing out the availablity of this feature


Leave your comments

Post comment as a guest

  • No comments found
Subscribe to the official OSBB BBM Channel!



Back to top