How to integrate the Symbian Camera application to a QtQuick application

A while ago Razvanpetru asked on #qt-symbian@freenode (you should come there too) how to use the Symbian camera application in a Qt app. So I wrote a small QML friendly Qt wrapper class to hide the nitty-gritty Symbian details. You can download the package here.

A few words about usage. First of all, the QtSDK 1.1 TP doesn’t contain all the necessary headers and libs that are needed for an application to use the native camera application. The needed stuff is included in a zip called newfileservice_patch.zip inside that package you downloaded. You need to extract it to your QtSDK’s Symbian environment. The Symbian environments are located in \QtSDK\Symbian\SDKs. In the 1.1 TP there are two environments – one for Symbian^1 and one for Symbian^3. The patch should fit them both. Just to make sure: do not extract to \QtSDK\Symbian\SDKs, but \QtSDK\Symbian\SDKs\Symbian(1/3)Qt471. In addition to the missing headers and libs it contains a fix to AiwVariant.h which had something that the GCCE version in the QtSDK toolchain didn’t like, so just overwrite the old one when you extract.

When you use the CameraApp class, remember to add UserEnvironment to your Symbian application’s list of capabilities. This is needed because the class uses the Symbian camera API to query the list of supported resolutions. Also you need to link to a few native Symbian libraries, so add this to your .pro file: “symbian: { LIBS += -lecam -lServiceHandler -lnewservice -lbafl }”. After that all you need to do is add cameraapp.h, cameraapp.cpp and cameraresolution.h to your project.

The class should work on desktop too which is handy if you have the same workflow as I do (develop on desktop and then test performance on actual device). When built for desktop the class returns dummy values which you can tweak in camerapp.h.

The usage is pretty simple. There are two methods (which are Q_INVOKABLE so you can call them from QML) to invoke the native camera application. One returns a full path to the image that was taken and the other a local file system URL. If the user canceled in the camera app, an empty string is returned. If something went wrong while trying to invoke the native camera app, the signal error is emitted. The two methods take the desired image width and height as parameters. The supported resolutions can be queried with the supportedResolutions method or by reading the supportedResolutions property in QML. In QML you’ll get a list of objects with width and height properties. You can use the list as a data model for a QML element or iterate it with javascript. AFAIK the native camera app doesn’t like any other values than the supported resolutions, so don’t try to feed it anything else.

That’s it. The zip contains an example application from which you can copy paste the relevant parts if you need to. The code is public domain so feel free to do anything you like with it. Now go make those imaging apps!

P.S. Anyone interested in collaboration to produce a “SymbianGaps” library which would address the things QtMobility is missing? I’m sure lots of new Qt developers not familiar Symbian would like to change profile, monitor the state of keyboard slider or virtual keyboard, pick a photo from the gallery, etc. Who’s in?

This entry was posted in Programming and tagged , , , , . Bookmark the permalink.

29 Responses to How to integrate the Symbian Camera application to a QtQuick application

  1. Truf says:

    Hi,

    Looks like http://juhaturunen.com/camerappintegration.zip
    is not exists:

    Not Found

    The requested URL /camerappintegration.zip was not found on this server.

  2. Pingback: Tweets that mention How to integrate the Symbian Camera application to a QtQuick application | Blogasdf -- Topsy.com

  3. Milot says:

    Can we make it work with Qt 4.6.3? Because there seems to be errors when building with Qt 4.6.3 and there is no directory like: \QtSDK\Symbian\SDKs\Symbian(1/3)Qt471 on current version of Qt which we can distribute to Ovi.

    • elpuri says:

      Yes you can. I don’t have the old QtSDK 1.0 anymore, but there should be a Symbian environment inside it just like QtSDK 1.1. Just look for the epoc32 directory.

  4. PoLLo says:

    Hey, I have some problems. I have Qt SDK 1.1 Beta Edtion that works with Qt 4.7.2 The project compiles ok and generates .sis file correctly. I’m using a Nokia 5800. The installation in the phone is OK, but when I try to run the app, it doesn’t run. What do you think the problem is??

    • Juha Turunen says:

      It doesn’t start at all or the camera doesn’t work? If it doesn’t start at all perhaps you’re missing some dependency on your device. Have you tried compiling and running some of the Qt examples or demos?

      • PoLLo says:

        I ran a single app made by myself with Bluetooth (using QBluetooth) example and it’s runs without problems. I have installed Qt, Qt Installer, QtMobility, QtWebkit from Qt SDK 1.1. Do I need another dependency??

  5. PoLLo says:

    Hey, now I can run the example, I only installed sqllite3.sis in my phone. But now, I am debugging with TRK and when I run the “camerapp” it runs but with the next message: [Qt Message] qrc:///qml/main.qml:10: ReferenceError: Can’t find variable: cameraApp. And only shows the exit button.

  6. Tomi says:

    The Qt Mobility version (1.1.1) that comes with Qt SDK 1.1 beta has bugs related to the camera API. Luckily, those bugs have already been fixed (in QtM 1.1.2) and the fixes are to be released with Qt SDK 1.1 RC.

    In the meanwhile, I suggest that you get the older mobility package for playing with the camera. For quick download of the QtM 1.1.0 sis package, see featured downloads of project Mirror House: https://projects.forum.nokia.com/mirrorhouse And enjoy the cool app as well :)

    Now, I have to confess that I did not examine the camera API integration app by Juha. Instead, I expect it to be using more or less the same APIs as the Mirror House demo app.

    • Juha Turunen says:

      The class doesn’t wrap the ECam APIs, but uses the NewFileService API to embed the native camera application UI.

  7. AdiraiBoy says:

    I tried this example on my N8. I use Qt version 4.7.3 and use QTSDK1.1 beta.
    It builds and installs fine on the device.
    But when clicking on the list, it tries to open the Camera and close it right away.
    I see the camera title on the top for one second.
    Any idea, what is going wrong or anything I am missing?

    Need help.

  8. adiraiboy says:

    TRAPD(err, result = fileClient->NewFileL( KUidCamera, *fileNames, NULL,
    ENewFileServiceImage, EFalse ));

    It’s on S^3 devi ces.

  9. ruizhen says:

    I can not run this app.
    NewFileServiceClient.h: No such file or directory
    Why?

    I use QtSDK 1.1.2

  10. ruizhen says:

    Sorry…I know why
    but this app run on C7 can’t not open camera
    I choose a resolution and the screen flash once,but doesn’t open the camera.

    I have installed QtMobility 1.1.3

  11. ruizhen says:

    OK,it works.
    but this app can not use photo editor
    after I take a picture,there are only two selection: select and delete,but I want to use the photo editor to cut the picture.

  12. Daker Fernandes Pinheiro says:

    How can I make it work on Qt SDK 2.2.1? It has no Symbian(1/3)Qt741 directory only a unique Symbian directory.

  13. gangaraju says:

    Hi,
    When I try build target release with gcce on device, getting error “cameraapp.cpp:80: error: ‘EGenericParamResolution’ was not declared in this scope”

    I cross checked, available release libs for ARMV5 only , can anybody post me for GCCE.

  14. gangaraju says:

    forgot to update I m working with QtSDK 1.1.3

  15. Bojan Komljenović says:

    I’ve completely solved the resolution problem.
    You can pass maximum resolution of your device camera, BUT you cannot pass it in the list as a single parameter.
    Above the resolution lines adding in the list, simply add following lines in symbianCapture function:

    TAiwVariant variant( EFalse );
    TAiwGenericParam param1( EGenericParamMMSSizeLimit, variant );
    paramList->AppendL( param1 );

    Apparently, when Symbian says it wants a list – it wants a freaking list!
    One item in a list object is not a list. Passing 2 parameters makes a list and there are no panic code errors.
    Works for me on all Symbian devices. :)

  16. Bojan Komljenović says:

    Forgot to say, do not be surprised on S^3 devices if you hardcode it to maximum resolution like me and it still doesn’t obey it.
    Good old Symbian will not allow you to use up more memory than it has available, so it will downgrade your maximum resolution in this use case if it must.
    Personally, I’ve never seen it go below 3MP on a C7 with 8MP EDoF camera…

  17. Hi!

    What about use native video and voice recording? Is it possible?

  18. Lincoln says:

    I read a lot of interesting posts here. Probably you spend a lot of time writing,
    i know how to save you a lot of time, there is an online tool that creates high quality, google friendly posts in minutes, just search in google –
    k2seotips unlimited content

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>