Developing in Cascades

Cascades

Jamie Julius is the Chief Software Architect of Nobex Technologies Inc. – Ed.

TITLE_IMAGE

About a month ago, I took the plunge and started a Cascades™ project for BlackBerry® 10.

Initially I was in a state of shock. This is an entirely different world compared to legacy BlackBerry Java® development – including the language (C++), the framework (Qt/Cascades), and a declarative language to build the UI (QML). Slowly and surely things started coming together. Fortunately, I had done a lot of C++ programming in my distant past, and somewhere in the back of my brain most of that old knowledge was still there. Nonetheless, I found myself staring at compiler error messages in bewilderment when I attempted to make a static function member call using dot syntax (Java) instead of using :: (C++).

After a couple of days the state of shock wore off and I found myself getting excited about this new way of writing BlackBerry applications. So what’s so great?

RIM® has been spotlighting Cascades with its cool controls and animation as a great framework for a new generation of apps. This is all true, but to me, what really makes the difference is the Qt foundation on which Cascades is built. It is Qt that enables rapid and solid development with a clean separation of the UI from the code behind.

In an attempt to summarize what I like about Qt, here’s a short list of the things that have made me smile so far. No doubt as I progress, the list will grow.

QML

Defining a UI via markup is more intuitive than defining it via code. The markup clearly expresses the hierarchical structure of the UI. Such a hierarchy is almost impossible to see when looking at the equivalent in code. Furthermore, the structure can be expressed with minimal lines of markup in contrast to hundreds of lines of code without any loss of functionality. Needless to say, tweaking the UI and finding and fixing bugs via markup are all a breeze. QML also supports components. This means that I can define QML fragments in separate files and refer to these components from other QML files. I have already found myself defining re-usable pieces of QML. Of course, QML isn’t the only markup language in use today for writing non-HTML applications (e.g., XAML), so it’s great to see this “tried and proven” concept come to the world of BlackBerry development.

Code Behind

QML wouldn’t be very useful if it didn’t connect well with C++ code. Qt’s support for named properties and invocable methods in C++ makes it really easy to put code behind the UI. The UI can easily be configured to read values from a C++ object exposed via “properties”. In fact, when configured as such, a control’s property is “bound” to an object’s property. This means that as the value of the object’s property changes, the UI automatically updates to reflect these changes. C++ objects can also expose “methods” which can be invoked directly from QML.

Qt Threading

Qt expands on the basic notion of a thread by providing a built-in event loop for any thread. Qt allows an object to be “associated” with a thread. Via dynamic method invocation, a method can be invoked on an object associated with another thread. When such invoked, Qt transparently wraps the method invocation in an event and places it in the appropriate thread’s event queue. As such, the method will be ultimately invoked on the object’s thread. I found this to be extremely helpful when dealing with a particular object type, containing long-running methods. If used correctly, one can use this technique to gain the benefits of multi-threading without the dangers of concurrency.

Signals and Slots

Qt uses a mechanism known as signals and slots to allow objects to “listen” to events triggered by other objects. I have found this mechanism to be much more flexible than the Java listener paradigm (i.e., implementing interfaces). Any object can be eligible to listen to “signals” of any other object, simply by implementing a method “slot” with the correct signature. Needless to say, should the receiving object be associated with a different thread, the invocation of the “slot” will be invoked on the object’s thread.

Maturity and Community Support

Qt is not new. That’s good! It’s good because it means that it is stable and mature. It means that it contains hundreds of classes providing everything from a basic string wrapper (QString) to XML processing (QDomDocument). It is also very well documented. Both officially on the Qt site and unofficially by the zillions of posts on various forums.

In short, I’m enjoying the ride. Qt is a great foundation for writing apps. Coupled with Cascades, I can definitely say that we have a strong framework for building the next generation of BlackBerry apps.

About Shadid

Application Development Consultant at Research In Motion (RIM), Shadid is a developer and more importantly a developer developer. He has been working closely with the dev community to help bring the best BlackBerry® experience to their applications. A key contributor in the Developer Relations team, Shadid is the lead contact for Location Bases Services, Sensors, Bluetooth and Deep Integration of Apps. Working with BlackBerry developers is not just his job but a passion he shares with the BlackBerry developer community.

Join the conversation

Show comments Hide comments
+ -
blog comments powered by Disqus