Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Posts: 27
Registered: ‎05-15-2012
My Device: Dev Alpha B
My Carrier: Bell

Re: BB10 camera viewfinder in ForeignWindow - SOLVED

Thank you Sean, my problem is resolved!

I am now able to see the viewfinder display correctly on my app. You were correct - I was doing manipulations in the createForeignWindow() method that was required for the viewfinder ( createForeignWindow() was provided with the ForeignWindow sample app, using the ForeignWindow is a different way). This resulted in mangling the handle for the viewfinder and creating another screen window that was not necessary at all.

Below is the series of instructions that worked for me:
1 - Create a ForeignWindow in QML (drag & drop feature from Momentics), give it an object name:
    objectName: "bufferForeignWindow"

2 - Get a handle on the ForeignWindow in code:
    mForeignWindow = mCameraPage->findChild<ForeignWindow*>("bufferForeignWindow");

3 - Disable auto frame updating


4 - Connect the windowAttached signal to a method in your object
    QObject::connect(mForeignWindow, SIGNAL(windowAttached(unsigned long, const QString&, const QString&)),
                 this, SLOT(onWindowAttached(unsigned long, const QString&, const QString& )));

5 - Generate a handle for the camera
    camera_error_t result = camera_open(CAMERA_UNIT_FRONT, CAMERA_MODE_RW, &mFrontCameraHandle);

6 - Associated the foreignWindow's handle with the newly generated one above

7 - Set the window group & ID from the foreignWindow created in QML
    result = camera_set_photovf_property( mFrontCameraHandle,
                                  CAMERA_IMGPROP_WIN_GROUPID, foreignWindowGroupId.toStdString().c_str(),
                                  CAMERA_IMGPROP_WIN_ID, foreignWindowId.toStdString().c_str() );

8 - Call the viewfinder to start doing its magic (viewFinderCallbackFunction_pre and viewFinderStatusFunction_ptr are function pointers, could be ignored and replaced by '0'.)
    camera_start_photo_viewfinder(mFrontCameraHandle, viewFinderCallbackFunction_ptr, viewFinderStatusFunction_ptr, 0);

9 - Implement your onWindowAttached slot for the QT connection in step 4, and setup the size, position and visibility of the view finder:
void CameraRenderThread:Smiley SurprisednWindowAttached (unsigned long win, const QString &group, const QString &id)
    qWarning() << "onWindowAttached entered.";
    // From this method, change window properties such as visibility, size and rotation…

    int size[] = {768, 400};

    screen_set_window_property_iv((screen_window_t)win, SCREEN_PROPERTY_SIZE, size);

    int pos[] = {0, 0};

    screen_set_window_property_iv((screen_window_t)win, SCREEN_PROPERTY_POSITION, pos);

    int i = 1;

    screen_set_window_property_iv((screen_window_t)win, SCREEN_PROPERTY_VISIBLE, &i);

    i = -1000;

    screen_set_window_property_iv((screen_window_t)win, SCREEN_PROPERTY_ZORDER, &i);


I hope this helps others get the camera's viewfinder up and running. Any questions please post.
Thanks again Sean for all the help,


Macadamian Technologies Inc.
BlackBerry Development Advisor
Posts: 683
Registered: ‎11-29-2011
My Device: PRIV
My Carrier: Rogers

Re: BB10 camera viewfinder in ForeignWindow - SOLVED

Glad this is now working for you.


I've worked through creating a cascades camera sample this weekend and I did run into one problem...

The ForeignWindow control has a bug in 10.0.4 which causes it to ignore detach events.  What this means is that once you attach a window to the ForeignWindow (eg. start the camera viewfinder), you cannot restart the camera again, because when the camera is stopped, the ForeignWindow still believes it is attached.

The workaround for this in 10.0.4 is to create your ForeignWindow in c++ dynamically, and when you are finished with it, delete, and re-create it so that it is back in it's initial disconnected state.


I am just working through some layout issues right now and should be able to post my example this week.