Table of Content
- Using Qt Creator for Qt Development on BlackBerry 10
- Getting Started
- Configuring QtCreator
- Creating Your First BlackBerry 10 Qt Project
- Editing Your Bar Descriptor File
- Package and Deploy Your Application Using Command line.
- Building and running Cascades based applications from Qt Creator
- How to make Qt Creator work with the Simulator
- Application permission
Using Qt Creator for Qt Development on BlackBerry 10
Qt is one of the application development frameworks available on BlackBerry 10 platform. Using Qt, you deploy your Qt C++ or Qt Quick application on BlackBerry 10 after rewriting all you graphical code. The current release of the BlackBerry 10 Gold NDK [developer.blackberry.com] includes Qt 4.8.4 for both simulator target (x86) and device target (arm) available for development. Compared to the development for the PlayBook, Qt is integrated in the BlackBerry DevAlpha [developer.blackberry.com] device firmware and can be used by Qt applications as shared libraries.
Note: this page is tailored to the Gold release of the NDK. The NDK is still in development. We will update this page in the course of development to cover new releases of NDK and QtCreator. The following steps were tested using Ubuntu 12.04 LTS 64 Bit but should work in a similar way on Windows/Mac.
Before starting with developing for BlackBerry 10 you need to download the following tools:
- The BlackBerry 10 Native SDK [developer.blackberry.com]
- The BlackBerry 10 Dev Alpha Simulator [developer.blackberry.com] if you don’t have a BlackBerry DevAlpha device [developer.blackberry.com]]
- BlackBerry signing code keys [blackberry.com] , not necessary for first steps into development using BlackBerry 10 Simulator
- QtCreator 2.7 (the required QNX plugin should be enabled by default). You can either clone it [qt.gitorious.org] or download a binary installer from [qt-project.org]. You can also download a recent build from Jenkins [builds.qt-project.org].
Enabling development mode
First of all, you have to enable development mode to be able to access your device to deploy and test software on it.
Refer to this article to see how to do that: http://developer.blackberry.com/native/documentation/bb10/enable_development_mode.html/
Note: if you’re under Linux, there’s one more step to be able to connect to the target machine: go to Settings->Storage and set “Usb connection” to “Connect to Windows” or “Connect to Mac”.
Getting the BlackBerry code signing keys
You need to obtain the BlackBerry signing code keys in order to sign your application, or to create a debugToken to run unsigned applications in development mode. The debugToken enables you to test your application on the device before signing it. Once your application is ready for publishing you should sign it.
Note: if you are using the BlackBerry 10 Dev Alpha Simulator, you don’t need to use the debugToken. So you can skip related steps below.
After you submitted a request to get the BlackBerry code signing keys, you should receive two “.cjs” registration files by email within the next few hours.
- “client-RDK-*.csj” – used to sign your applications and publish to the BlackBerry App World storefront.
- “client-PBDT-*.csj” – used to generate a debug token that you can use to test your application on a device.
Note: if you are using Qt Creator 2.7 or higher, you can register directly using the new BlackBerry Settings page as explained in the next section. So you can skip the instructions below.
Once you receive those files, register them with the RIM Signing Authority using the following command line:
- $ blackberry-signer -register -csjpin <csj pin> -storepass <KeystorePassword> <client-RDK-xxxxxx.csj file> <client-PBDT-xxxxx.csj file>
where the “<cjs pin>” is the PIN you specified on the web form when requesting the code signing keys and the “<KeystorePassword>” is a password you specify for the keystore.
For more details about signing please refer to Signing Setup Guide [developer.blackberry.com]
Then you create a debugToken file for your device as follows:
- $ blackberry-debugtokenrequest -storepass <KeystorePassword> -devicepin <device PIN> <debug_token_file_name.bar>
You can find the “<device PIN>” on your device or in simulator under “Settings \-> About \-> Hardware”
Your next steps are to install the new debugToken into your device :
- $ blackberry-deploy -installDebugToken <path to debug token> -device <IP address of device> -password <device password>
For more details on the debugToken please refer to this article [developer.blackberry.com]
The QtCreator 2.7 brings new features for the BlackBerry 10 plugin (currently called “Qnx”) that enables you to easily create, build, deploy and debug your application directly from the IDE. Please make sure you use the 2.7 version or a recent build of QtCreator. Here are the new features that the BlackBerry 10 plugin provides for 2.7:
- Easy setup of the your BlackBerry 10 development environment (Kits, Qt Version, Compiler, …).
- Support for the BlackBerry Signing code process to register and create a developer certificate and generate a debugToken to upload your apps into the device.
- UI editor for the bar descriptor file to easily manage the application’s appearance and behavior when running on the device.
Using QtCreator 2.7
Note: If you are using QtCreator 2.6 we highly recommend you to download the version 2.7 which hugely simplifies the setup of your BlackBerry 10 plugin. By consequence, we won’t cover the use of QtCreator 2.6 in the current article.
If you already have a QtCreator 2.7 installed on you machine, please follow the steps below:
- Select Tools > Options > BlackBerry > NDK (on Mac: Preferences > BlackBerry > NDK) and set the path to your NDK. This will generate a Qt version, a Compiler and two Kits (one for the device and another for the simulator) based on your NDK.
- Select Tools > Options > BlackBerry > Keys (on Mac: Preferences > BlackBerry > Keys) to register and create a developer certificate. To register you need to set the path to your registration files and the PIN code you specified when requesting the signing keys.
- Select Tools > Options > Devices > Add > Blackberry Device (on Mac: Preferences > Devices > Add > Blackberry Device) to add a BlackBerry Device. You can add either the physical device or the simulator.
- Create and upload a debug token bar file when adding the device from the wizard.
Note: The signing code support in QtCreator is under development and will be improved in the future.
Using a recent QtCreator build
You can also download a nightly build of QtCreator from http://builds.qt-project.org.
It contains some improvements planned for 2.8 which are not available in the 2.7.x release versions.
Known issues with QtCreator 2.7
Below are few known issues with the Qnx plugin in QtCreator 2.7 release, which should be fixed in the next 2.7.1 release:
- If you create a new project, select a BlackBerry Kit and build in a release mode only, QtCreator will fail to create the package as it will try to find the bar-descriptor file in a debug build repository. Make sure you selected a debug build to avoid this issue.
- If you create a Qt5 project, QtCreator will generate a bar descriptor in order to create the application’s package. You need to add the following lines to your bar descriptor in order for the application to run correclty:
We recommend to use a nightly Qt Creator build which already contains fixes for the issues above.
Creating Your First BlackBerry 10 Qt Project
You can create a Qt application by selecting one of project templates in the “new project” wizard. Additionally, The BlackBerry plugin provides extra templates for Cascades projects and Qt GUI applications using BlackBerry 10 custom styles.
For example, if you create a Qt Quick Application and use the Kit you defined for BlackBerry Qt Creator will automatically generate a bar descriptor file and ask you if you want to add it into your project. You can then use the bar descriptor UI editor to edit your application’s bar descriptor file.
Deploying Qt5 Applications
If you are using Qt5, Qt Creator will generate a bar descriptor file to deploy your Qt5 libraries and create the application’s package. As currenlty Qt5 libraries are not shipped in the BlackBerry 10 devices, you need to deploy them into your package.
The following lines in the generated bar descriptor will copy and deploy your Qt5 libraries, imports and plugins automatically from your Qt5 installation directory:
- <env value="app/native/imports" var="QML2_IMPORT_PATH"/>
- <env value="app/native/plugins" var="QT_PLUGIN_PATH"/>
- <env value="app/native/lib" var="LD_LIBRARY_PATH"/>
- <asset path="%QT_INSTALL_PLUGINS%">plugins</asset>
- <asset path="%QT_INSTALL_QML%">imports</asset>
- <asset path="%QT_INSTALL_LIBS%">lib</asset>
Note that, for security reasons, the nativepackager doesn’t consider symbolic links. This will cause each Qt library to be copied four times and increase significantly the package size. We will provide in the near future a bar file containing the Qt5 libraries, so that you don’t have to deploy them into your packages.
Note: You can exclude the Qt libraries you don’t use to decrease your package size. For that, you can use the <exclude> element and sepcify the libraries to exclude as shown in the example below:
- <env value="app/native/lib" var="LD_LIBRARY_PATH"/>
- <asset path="%QT_INSTALL_LIBS%">
- <exclude name="libQt5Xml.so.5.1.0"/>
- <exclude name="libQt5QuickParticles.so.5.1.0"/>
- <exclude name="libQt5Test.so.5.1.0"/>
Editing Your Bar Descriptor File
The “bar-descriptor.xml” file specifies the parameters for identifying, installing, and launching native applications on BlackBerry 10. It mainly contains information about the application author, id, icons and other properties and is used to create the BAR file or BAR package. A BAR package is a installation package of an application for the BlackBerry 10 platform. “BAR” stands for “ B lackberry A pplication a R chive”. For more details please refer to this page [developer.blackberry.com]
QtCreator 2.7 provides a new UI editor to easily edit your bar descriptor and manage your application’s behavior and appearance.
Note: the generated bar descriptor file will be called bar-descriptor.xml and will be used by QtCreator to generate a final bar descriptor in the build directory to package your application.
If you run the application now, QtCreator will create the bar package, connect to the device or to the simulator and launch your application. You can also do these steps using commands in a shell, see the next section for more details.
For performance reasons, the log output from qWarning, qDebug, etc is captured by the “slog2” logging system on BlackBerry 10 instead of plain text files in the file system. In the actual release the messages will appear unfiltered in the “Application Output”.
Package and Deploy Your Application Using Command line.
You can use NDK command line tools to package and deploy your application instead QtCreator if needed:
- create the package in devMode:
- $ blackberry-nativepackager -devMode -package <package_name.bar> <bar-descriptor.xml> -debugToken <debug_Token_file.bar>
- create the package in Signing mode:
- $ blackberry-nativepackager -package <package_name.bar> <bar-descriptor.xml>
- sign your application (not needed in the devMode):
- $ blackberry-signer -storepass <KeyStorePassword> <package_name.bar>
- deploy on the device:
- $ blackberry-deploy -installApp -package <package_name.bar> -device <device_ip> -password <device_password>
- in case you don’t like what you see, you can remove the application:
- $ blackberry-deploy -uninstallApp -package <package_name.bar> -device <device_ip> -password <device_password>
Building and running Cascades based applications from Qt Creator
These configuration has been tested on Linux Debian Wheezy (64 bits) and Opensuse 12.2 with BB10 Gold NDK and deployment on a Simulator and device.
In order to build Cascades applications, you need to adapt your bar-descriptor.xml file, as well as tweaking Qt Creator settings a bit. From now, we assume that you are able to build a Qt Quick application, and able to deploy it. Those using simulator and that are unable to launch the application, even if it compiles and is deployed, should refer to the next section.
Note that using Cascades in your application is more involved than just adding “import bb.cascades 1.0” to your QML files. See the Cascades Documentation [developer.blackberry.com] to learn how to write Cascades based applications.
Packaging and deployment options
When using cascades, some precautions have to be taken for packaging your application. You first have to respect a specific folder layout, where all shipped files, that includes images files like icons, and QML files, should be in a subfolder called assets.
The bar-descriptior.xml file should also be adapted to take the different targets in account. Here is an example of descriptor file including only the simulator as a debug target
- <?xml version='1.0' encoding='utf-8' standalone='no'?>
- <qnx >
- <env value="app/native/imports" var="QML_IMPORT_PATH"/>
- <env value="app/native/qml" var="QML2_IMPORT_PATH"/>
- <env value="app/native/plugins:/usr/lib/qt4/plugins" var="QT_PLUGIN_PATH"/>
- <env value="app/native/lib:/usr/lib/qt4/lib/" var="LD_LIBRARY_PATH"/>
- <action system="true">run_native</action>
- <configuration name="Simulator-Debug">
- <asset path="%SRC_DIR%/path/to/build/folder/o-g/app" entry="true" type="Qnx/Elf">app</asset>
- <!-- omit the above "Simulator-Debug" configuration section and add the line below if using device only
- <asset path="app" entry="true" type="Qnx/Elf">app</asset>
- <asset path="%SRC_DIR%/assets">assets</asset>
You can take inspiration on descriptor files that the SDK generates to get other targets. But take care of the o-g folder in which the debug binaries will be compiled for the simulator. Other binaries have their own folder.
In the project file, you needs to add cascades options. You can also add import path, that provides autocompletion in C++ editor. QML autocompletion does not work out of box for now, but a workaround exists [qt-project.org]. The following template contains all the settings that should be added.
- TEMPLATE = app
- TARGET = app
- QT = ...
- CONFIG += cascades10
- # Horrible workaround because INCLUDEPATH do not work with
- # absolute path under Linux + QtCreator 2.6 ???
- INCLUDEPATH += ../../../relative/path/<target>/qnx6/usr/include
- INCLUDEPATH += ../../../relative/path/<target>/qnx6/usr/include/qt4
- HEADERS = ...
- SOURCES += ...
- OTHER_FILES += bar-descriptor.xml \
- assets/main.qml \
Some additional settings have to be passed to qmake in order to make the compilation to work. First, if you didn’t add the BB10 kit, you should add it. It will provide automatically the compilation recipe and the testing on a device. In order to compile cascades based applications, you need to add a QMake option, that is
for a device, or
- -spec blackberry-x86-qcc CONFIG+=simulator
for the simulator.
With these options, compiling a cascades based application, and deploying it should work.
How to make Qt Creator work with the Simulator
Setting the simulator as a device is easy, and can be done as if it was a real device. However, the simulator is X86-based, and the default settings for compiling a Qt project with Qt Creator are those for arm devices. In order to compile for X86, you have to change the MKSPEC, and it is done by passing
- -spec blackberry-x86-qcc
to the QMake additionnal arguments. With this spec set, it will override the default spec and compile for X86.
You can add some permission to the application by tweaking the bar-description.xml file by adding the line
or the following line for permission identifier that is mark * in the list below
- <permission system="true">permission_identifier</permission>
Here’s a list of permission identifier
- Permission – Identifier
- Internet – access_internet
- Location – access_location_services
- Microphone – record_audio
- Notebooks – access_pimdomain_notebooks
- Post Notifications – post_notification
- Push – _sys_use_consumer_push *
- Run when background – run_when_backgrounded
- Shared Files – access_shared
- Text Messages – access_sms_mms
- Blackberry Messenger – bbm_connect
- Calender – access_pimdomain_calendars
- Camera – use_camera
- Contacts – access_pimdomain_contacts
- Device Identifying Information – read_device_identifying_information
- Email and PIN messages – access_pimdomain_messages
- GPS Location – read_geolocation