Wednesday, 7 March 2012

QTHelloWorld in Momentics IDE for MS Windows users

Want to start developing/porting Qt apps to Blackberry Playbook but don't want to dive into Qt libraries compilation? If yes then this article is for you, it lets you jump directly to developing Qt app skipping tedious process of compiling Qt libraries first.
We'll be speaking here only about creating Qt application to be deployed to Blackberry Playbook Simulator (Qt library below is compiled for x86 architecture).

1. Prepare your MS Windows system
1.1. Download Native SDK for Tablet OS 2.0 from here and install - very straitforward process.
1.2. Create a folder C:\qt-x86-lib (you can create a folder wherever you want, this path will be used in this article)
1.3. Download Qt library from and save it into C:\qt-x86-lib\ folder created in 1.2. This is a set of Qt libraries precompiled for x86 platform and suitable only for Simulator. This is not something that is being built nightly but it's fresh above and proved to work. Probably with time if there is enough interest in the project I'll setup something more serious to follow current Qt development repository.
1.4. Unpack qt-x86-lib.tgz archive using any archivator that understands .tgz format (my favorite one is 7zip). You should get C:\qt-x86-lib\stage\... and lots of files/folders underneath.

That's basically it, now you can start develop Qt app.

2. Create QTHelloWorld project in Momentics IDE
Start Momentics IDE.
Click File->New->BlackBerry Tablet OS C/C++ Project and in Project Name: specify QTHelloWorld, hit Next and Basic Setting will open.
- check Language: C++
- Build Style: Managed build
- Project Type: Application-Empty Application
Click Next and Build Configurations will open, we want Simulator-Debug here. Click Finish.
At this point we have an empty project with bar-descriptor opened for you in IDE. You can put whatever you want at General Page:

Click Assets tab and then make sure to select Simulator-Debug at Build Configurations panel. Then click Add Files... then File System... and select your that you should have in qt-x86-lib\stage\nto\x86\usr\lib\qt4\lib\. Do the same for, Now add one more file: C:\qt-x86-lib\stage\nto\x86\usr\lib\qt4\plugins\platforms\ Now we have to correct one line in bar-descriptor.xml. Click on Source tab and locate the line
<asset path="C:/qt-x86-lib/stage/nto/x86/usr/lib/qt4/plugins/platforms/" type="Qnx/Elf">lib/</asset>
Change it to:
<asset path="C:/qt-x86-lib/stage/nto/x86/usr/lib/qt4/plugins/platforms/" type="Qnx/Elf">lib/platforms/</asset>
Click File->Save all...

Now you should have picture similar to this:

Now let's add source file main.cpp to the project. Right click on src folder in Project Explorer and choos New->Source file, in Source File: field put main.cpp and hit Finish.

Main.cpp will be opened for you, copy paste following code:
#include <QApplication>
#include <QPushButton>
#include <QWidget>

int main(int argc, char *argv[])
    qputenv("QT_QPA_FONTDIR", "/usr/fonts/font_repository/monotype");

    QApplication app(argc, argv);

    QWidget window;
    window.resize(1024, 600);

    QPushButton quit("Quit", &window);
    quit.setGeometry(422, 100, 180, 40);
    QObject::connect(&quit, SIGNAL(clicked()), &app, SLOT(quit()));;
    return app.exec();
Click File->Save all...

Now it is time to change some compiler/linker settings. Right click on QTHelloWorld in Project Explorer and choose Properties. Make sure you set up right things in Configuration:, Include Directories (-l) and Defines (-D) as shown on the picture:

Now set up your libraries this way:

Click Ok.
Let's try to build - click Project->Build Project. In Console you should eventually see "Build complete for project QTHelloWorld". Congratulations! it's already something... 
Now hit Run->Debug Configurations... You need to specify -platform blackberry at Arguments tab. And at Environment tab check that you have LD_LIBRARY_PATH=app/native/lib (sometimes it is missing, don't know why). Click 'Debug' and after the project is packaged and deployed to your Simulator you will be switched to Debug Perspective and the program execution will stop at main().

Now you know what to do -) Enjoy!

PS: many thanks to who gave me the very first hint how to start.


  1. I already built Qt for ARM 7 LE and I want to run your tutorial on my playbook. I've been following your instructions (make adjustment and point to compiled Qt for ARM 7LE) and it is directed to device debug. When I tried to build, there are several errors like below. Do you have any idea? am I missing something?

    building output:

    Thanks for your insight

    1. I made improvement but still experiencing error like below, I don't know why the linker is not working

      qcc -o QtHelloWorld src\main.o -lQtCore -lQtGui -lQtOpenGL -V4.4.2,gcc_ntoarmv7le_cpp -w1 -lang-c++ -g -Wl,-z,relro -Wl,-z,now -Ld:/bbndk-2.0.0/target/qnx6/../target-override/armle-v7/lib -Ld:/bbndk-2.0.0/target/qnx6/../target-override/armle-v7/usr/lib -LC:\Users\Oscar\Documents\BlackBerry\Qt\stage\nto\armle-v7\usr\lib\qt4\lib
      d:\bbndk-2.0.0\host\win32\x86\usr\bin\ntoarm-ld: cannot find -lQtCore
      cc: d:/bbndk-2.0.0/host/win32/x86/usr/bin/ntoarm-ld caught signal 1
      Build error occurred, build is stopped
      Time consumed: 3723 ms.

  2. You Library Path setting is wrong and linker can't find Qt Libraries (the first one is QtCore). Please make sure you have correct Library Path for Configuration: Device-Debug in your NDK settings.

  3. where i can find compiled libraries for playbook device, no x86 emulator ? or how to compile them under windows 7 ? thx

    1. You can download Qt libraries for Playbook from here

  4. thx very much. it's working flawlessly. now i only need pb support for qt creator under windows, which seems not possible at this moment.