Fun things you can do with the Nokia Qt SDK

Recently I presented a small Qt 4.6 based demo on the LinuxTag in Berlin, as an example of something you could do with the Nokia Qt SDK. It combined existing projects like the Tiled map editor and the Box2D physics library with Qt Mobility's sensors API for reading out the accelerometer. It looks like this on the N900:

Andreas has demonstrated before that integrating Box2D and QGraphicsView is easy. In this demo I have used the generic object layer support in the Tiled map editor to conveniently define the starting points and properties of some boxes, including the definition of the colliding parts of the rather minimal tile based background.

The big red boxes around the sides are a quick hack to prevent any of the dynamic boxes from leaving the scene. Since indeed, turning your device will change the gravity applied to the boxes as appropriate. This was the first time I've used an accelerometer and I expected it to be somewhat more complicated, but combining the sensors API in Qt Mobility with Box2D was as easy as:

    QAccelerometerReading *reading = mAccelerometer->reading();
b2Vec2 gravity(-reading->x(), -reading->y());
mWorld->SetGravity(gravity);

As documented, the accelerometer gives us the force applied to the device relative to freefall. When the device is in rest, this is the exact opposite of the applied gravitational force. Hence we have to reverse the x and y readings when turning them into the gravitational force applied to the Box2D world. One little caveat: as of Qt Mobility 1.0 the application will need to run as root on the N900 to be able to get any values out of the accelerometer. This is bug QTMOBILITY-326.

Here is the demo in action:

The complete sources of this demo are available on gitorious.org, on the 'qtarcade' branch. The repository includes the necessary classes from Tiled and Box2D so that it's easy to try it out.

With Qt Creator 2.0 and the Nokia Qt SDK 1.0 released last week, it could not be easier to start hacking and implement your own crazy ideas. Who will be the first to get his cool Qt app signed for free and distributed on the Ovi store?


Blog Topics:

Comments

Commenting for this post has ended.

?
Ghita
0 points
180 months ago

Tried to compile it with latest Nokia Qt SDK but under simulator target it does not work: missing zlib.h not found (it seems that zlib not present for that target) Any help ?

?
AlexBravo
0 points
180 months ago

@Ghita You can go to Projects | Build environment and add ;C:NokiaQtSDKSymbianSDKsrc3rdpartyzlib;
at the end of INCLUDE variable.
I'm just curious, are you using Win 7?

?
Ghita
0 points
180 months ago

@AlexBravo tried using QtCreator 2.0 but INCLUDE was not there so had to add it. The location was OK but still same error. Also I shhould specify the lib location for linkage maybe ?

?
Ghita
0 points
180 months ago

Also I use win XP

?
Ghita
0 points
180 months ago

Managed to sove my problem by specifying INCLUDEPATH += $$PWD; d:NokiaQtSDKSymbianSDKsrc3rdpartyzlib in tiled.prj file

?
Ghita
0 points
180 months ago

Does accelerometer work in simulator for anyone. When I rotate the device (using the slider for acc values) nothing happens, only layout changes and this one is quite tricky for maemo device

?
Thorbjørn Lindeijer
0 points
180 months ago

I guess I should make the zlib requirement optional since it's creating quite some trouble, which is understandable. I already have the following line in src.pro:

win32:INCLUDEPATH += $$(QTDIR)/src/3rdparty/zlib

But this does not work with an "installed" Qt, which it seems the Nokia Qt SDK is using, so the $$(QTDIR) part indeed needs to be changed to the NokiaQtSDKSymbianSDK one. I'm not sure if it would be possible to write the .pro file in a way that'll work for everybody.

So, next time I'll use a simple CSV format instead of compressing the map data, or use qCompress/qUncompress to avoid direct dependency on zlib.

@Ghita: The accelerometer sliders in the simulator worked for me. Using the "rotate device" feature may have strange results since I don't handle device rotation in this application.

?
Ghita
0 points
179 months ago

Thorbjørn Lindeijer wrote:
"The accelerometer sliders in the simulator worked for me. Using the "rotate device" feature may have strange results since I don't handle device rotation in this application."

I was mentioning about device rotate issue because I thought to be an issue with the simulator ( I think than in one of the simulated devices: Maemo or Symbian in worked better) On your video (couldn't try it on a device myself) the landscape of the "world" remain the same, so no issue with rotation.. the rotation was kind of ignored from the point of view of the landscape (only acceleration seems to have changed the direction)

?
dyams
0 points
178 months ago

The objects wont respond when they not moving. Respond in the sense respond to accelerometer.
Any hints please!

?
midday
0 points
177 months ago

What does it mean "is very unoptimized for OpenGL" ?
Where i can read about optimization to OpenGL ?
It is possible to optimize this example? If yes, Please teach us =)

?
GuidoSeifert
-1 points
180 months ago

Great! But I really start to hate my N900. It gives me serious trouble. :-(
The trouble is: I really don't know what to code first. :-D

?
scorp1us
-1 points
180 months ago

Not to undermine you all, but I'd rather be doing QML in QtCreator 2.1, in the Nokia SDK.

Speaking of which, any idea when we'll get that?

?
vivaladav
-1 points
180 months ago

cool! What's the framerate on the N900? What about the other phones?

?
AlexBravo
-1 points
180 months ago

It's just amazing how easy you guys are making things for developers.
N900 simulator is great and much faster than Emulator.

It took literally 7 minutes to get this app running in N900 Simulator (don't forget to turn it in landscape mode or pieces fall out throuth the hole in the red border.).

That time inludes fixing a couple of compilation issues with adding include path to zlib.h and adding

define M_PI 3.14159265358979323846

to box2body.cpp

I'm starting to think Qt Creator is going to beat XCode soon. Especially considering you don't have to learn non-mainstream Objective-C.

Development with Qt is becoming really exciting!

?
scorp1us
-1 points
180 months ago

QtCreator is the bomb, but it needs python (PySide/PyQt) and javascript (QtScript) editing/parsing functions. I can haz dem for 2.2?

?
george
-1 points
180 months ago

does any one know where I can get hold of any early Qt documentation (~1994)?

thanks in advance

?
Alex Savin
-1 points
180 months ago

Looks good. Tried to compile and run it via Qt Creator 2.0 on N900. I'm getting this thing:

loaded the Generic plugin
loaded the N900 plugin
Could not start sensor:
Sensor not active!
Aborted

Wonder what might be wrong?

?
Harald Fernengel
-1 points
180 months ago

@Alex: Check the blog where it says "the application will need to run as root on the N900 to be able to get any values out of the accelerometer". We hope to get a fix ASAP.

?
Kamalakshan
-1 points
180 months ago

It might be due to the bug QTMOBILITY-326.

?
Danny77
-1 points
180 months ago

@AlexBravo Isn't M_PI a standard define in math.h/cmath? Odd that should have to define it again.

"I'm starting to think Qt Creator is going to beat XCode soon. Especially considering you don't have to learn non-mainstream Objective-C."

Creator already beats XCode as a C++ IDE (although project management is still weak). Although XCode is fantastic for Cocoa development. BTW, you don't need to use Objective-C exclusively to build a Cocoa app - you can use standard C/C++ and just use Obj-C for the interface. Just saying.

?
Alex Savin
-1 points
180 months ago

>the application will need to run as root on the N900 to be able to get any values out of the accelerometer

Aren't applications run as root via MADDE? How root run can be enabled?

?
Thorbjørn Lindeijer
-1 points
180 months ago

@Alex Savin: You "enable root run" by simply logging in on your N900 as root, before executing the application. In order to do this from Qt Creator, edit your Maemo device configuration (found in Settings under Projects) and change the user to 'root' and the password to whatever password you set your root password to when you installed 'rootsh' on your device. Please note however that this is an ugly hack. Don't run your applications as root in general, since then you risk destroying your device with a programming error.

@vivaladav: I've quickly done a quick measurement on the framerate and it was 60 fps, which is unsurprising since that's what the logic timer is set to (CPU usage was at 50% with all boxes moving). I've done another measurement with the logic timer set to 1000. This wasn't reachable, but yielded a logic rate of generally 150-200 and a framerate of about 120 fps when all boxes were moving. You'll generally want to cap it at 60 though. :-)

Note that this is using the raster graphics engine, which appears to be the default on the N900. Running the demo in a QGLWidget took the framerate down to 60 fps again but with a higher CPU load, since this demo is very unoptimized for OpenGL and not doing anything that would be faster in OpenGL either.

@scorp1us: I'd rather be doing QML as well, and as you can see from the repository this demo is a backport from a similar demo integrating Tiled maps and Box2D in QML. However, indeed we'll get to that once we have a Nokia Qt SDK based on Qt 4.7 out. Btw, as part of the QML support in Qt Creator you'll definitely see improvements for editing JavaScript in general as well. As far as Python is concerned, 2.2 will have a highlighter and code folding based on Kate syntax files, at least.

?
multiHYP
-1 points
180 months ago

Awesome guys, the Nokia SDK is out for mac. I for one can't get enough, please more, more and more...
One issue though, the editor doesn't behave like eclipse's editor which is cumbersome at times. For instance the commenting of text selection (CTRL+/) that does start and end the comment by /* and */ or the myVariableName (CTRL+ARROW_KEYS) selection doesn't take the capitalisations of the name into consideration.
Other than that, Qt is better than Visual Studio and Xcode put together hands down! :D

?
Alex Savin
-1 points
180 months ago

@Thorbjørn Lindeijer: Yay, it helped, thanks!