Wednesday 15 February 2012

QTHelloWorld in Momentics IDE for Blackberry Playbook

1. Build QT library for Playbook Simulator
For simplicity let's assume you are using /qt-x86-lib folder (x86 because you are building for Simulator)
$ cd /qt-x86-lib
$ git clone https://BGmot@github.com/BGmot/Qt.git
...git will work here for you...
$ cd Qt

My Momentics IDE is installed in /Developer/SDKs/bbndk-2.0/, adjust the next line according to your setup.
$ source /Developer/SDKs/bbndk-2.0/bbndk-env.sh
$ ./configure-qsk x86
...lot's of output...
$ make
... here you can go drink some coffee/beer/whatever you prefer/watch favorite movie...
$ make install
...lot's of output...

At this point you should have all QT libraries compiled for x86 architecture. Let's check it.
$ ls -l /qt-x86-lib/Qt/stage/nto/x86/usr/lib/qt4/lib
drwxr-xr-x  84 eyurchen  domusers      2856 Feb  9 14:28 fonts
-rw-r--r--   1 eyurchen  domusers       922 Feb 10 11:13 libQtCore.la
-rw-r--r--   1 eyurchen  domusers       872 Feb 10 11:13 libQtCore.prl
lrwxr-xr-x   1 eyurchen  domusers        18 Feb 10 11:13 libQtCore.so -> libQtCore.so.4.8.0
lrwxr-xr-x   1 eyurchen  domusers        18 Feb 10 11:13 libQtCore.so.4 -> libQtCore.so.4.8.0
lrwxr-xr-x   1 eyurchen  domusers        18 Feb 10 11:13 libQtCore.so.4.8 -> libQtCore.so.4.8.0
-rwxr-xr-x   1 eyurchen  domusers   3193036 Feb 10 11:13 libQtCore.so.4.8.0
...
You should have similar output.


2. Create QTHelloWorld project in Momentics IDE
Download/Install/Start Momentics 2.0
Click File->New->BlackBerry Tablet OS C/C++ Project and in Project Name: specify QTHelloWorld, hit Next and Basic Setting will open.
Here:
- 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 libQTCore.so library that you built in /qt-x86-lib/Qt/stage/nto/x86/usr/lib/qt4/lib. Do the same for libQtGui.so, libQtOpenGL.so. Now add one more file: /qt-x86-lib/Qt/stage/nto/x86/usr/lib/qt4/plugins/platforms/libblackberry.so. Now you should have picture similar to this:

Now we have to correct one line in bar-descriptor.xml. Click on Source tab and locate the line
<asset path="/qt-x86-lib/Qt/stage/nto/x86/usr/lib/qt4/plugins/platforms/libblackberry.so" type="Qnx/Elf">lib/libblackberry.so</asset>

Change it to:
<asset path="/qt-x86-lib/Qt/stage/nto/x86/usr/lib/qt4/plugins/platforms/libblackberry.so" type="Qnx/Elf">lib/platforms/libblackberry.so</asset>
Click File->Save all...

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[])
{
    QCoreApplication::addLibraryPath("app/native/lib");
    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()));

    window.show();
    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 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 http://hecgeek.blogspot.com/2011/10/qt-for-blackberry-playbook.html who gave me the very first hint how to start.