Welcome!

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

Reply
Contributor
Posts: 16
Registered: ‎05-30-2013
My Device: Z10, Q10
My Carrier: Rogers

Camera from C++ to QML through foreign window

Hey everyone,

 

I'm developing a camera app and one of my main goals is to create the UI in qml, however, in order to get all features that I need my only option is to use the camera handle from C++, and this is my problem.

 

I was looking for example and I think my solution is this: Create the whole app in qml, but create the camera in C++ and use a foreign window to show it. I saw this example: https://github.com/blackberry/Cascades-Samples/tree/master/helloforeignwindow but it's not really clear to me. There's a whole bunch of code and when it finally comes to show something (noise) trough the foreign window a buffer is made pixel by pixel and them just exported...

 

Do you have any suggestion or any idea of how I can do that? I mean, creating the interface in qml, the camera in C++ and connect them using a foreign window?

 

Thank you.

Retired
Posts: 749
Registered: ‎12-16-2008
My Device: BlackBerry Z30
My Carrier: Bell

Re: Camera from C++ to QML through foreign window

There are actually a few examples that do exactly this. Check out http://blackberry.github.io/Community/Camera.html

Paul Bernhardt
Application Development Consultant
BlackBerry
@PBernhardt

Did this answer your question? Please accept this post as the solution.
Found a bug? Report it to the Developer Issue Tracker
Contributor
Posts: 16
Registered: ‎05-30-2013
My Device: Z10, Q10
My Carrier: Rogers

Re: Camera from C++ to QML through foreign window

[ Edited ]

Thank you very much!

 

And also, it may sound as a silly question but on the HelloCamera sample I'm able to use the cascades components  to connect with the camera, which means, I'm not using QML, right?

 

Is that possible to build the whole UI (buttons, pages, fancy stuff...) in QML and then use the camera as in the HelloCamera sample?

Retired
Posts: 749
Registered: ‎12-16-2008
My Device: BlackBerry Z30
My Carrier: Bell

Re: Camera from C++ to QML through foreign window

[ Edited ]

Yes, that is quite possible, and is in fact the recommended approach if you need access to the features only provided in the lower level C camera API (like burst capture or facial detection)

Paul Bernhardt
Application Development Consultant
BlackBerry
@PBernhardt

Did this answer your question? Please accept this post as the solution.
Found a bug? Report it to the Developer Issue Tracker
Contributor
Posts: 16
Registered: ‎05-30-2013
My Device: Z10, Q10
My Carrier: Rogers

Re: Camera from C++ to QML through foreign window

Well, after few days working on it I finally got the whole UI written in QML and the camera in C++, however there's some "simple" things that just turned into nightmares... For example the focus status.

 

Let's say that I have one image in QML that will change according to the focus states (locked, searching, failed), how is it possible to make a function that will check the camera focus state, which is just a ENUM, and change the image when this variable changes? Specially how can I implement it if the actual code running will be the QML code instead of the C++ and QML cannot "see" this variable changing in the same way as it would see a QML camera signal?

Retired
Posts: 749
Registered: ‎12-16-2008
My Device: BlackBerry Z30
My Carrier: Bell

Re: Camera from C++ to QML through foreign window

There are a number of ways to connect C++ and QML together, take a look here: https://developer.blackberry.com/cascades/documentation/dev/integrating_cpp_qml/index.html

 

Paul Bernhardt
Application Development Consultant
BlackBerry
@PBernhardt

Did this answer your question? Please accept this post as the solution.
Found a bug? Report it to the Developer Issue Tracker
Contributor
Posts: 16
Registered: ‎05-30-2013
My Device: Z10, Q10
My Carrier: Rogers

Re: Camera from C++ to QML through foreign window

Yes, but all those examples are about exposing C++ code to QML. It's a little bit hard to describe, but it's not what I'm trying to do. The focus status that I mentioned is a good example. I have a change in C++ layer that will affect the QML layer, and not the opposite like in the examples in that link.

 

My main point here is: How to keep track of such camera variables in C++ when using a QML UI?

 

I'm trying several different approaches but unsuccessfully =/ 

Developer
Posts: 828
Registered: ‎10-16-2012
My Device: Red Z10
My Carrier: Rogers

Re: Camera from C++ to QML through foreign window

[ Edited ]

you can keep track of c++ variables in qml by creating a label or something that supports text in qml and then have the value updated to the qml label via c++

 

qml

Label {
      id: qmlLabel
      objectName: "qmlLabel"
onTextChanged: {
//store text in a variable if needed for later
} }

 c++

//pull qml label
Label *label = bb::cascades::Application::instance()->findChild<Label*>("qmlLabel");

//update whenever needed label->setText(myC++variable.toString());
Retired
Posts: 749
Registered: ‎12-16-2008
My Device: BlackBerry Z30
My Carrier: Bell

Re: Camera from C++ to QML through foreign window

FindChild is often not the best way to do things, as it ties your C code to your UI. It makes it much harder to modify your UI later. Best practices are to provide a C object or property to QML, and then modify it from QML.

 

What you could do is use the approach from the Exposing C++ values and Objects to QML section. You can go very basic and just provide a QDeclarativePropertyMap, which would let you read or modify it's properties in C++ and QML, or create a custom object with your own set of properties and any custom signals and slots you want.

 

For example, if you use the MyCppClass example, because you have a Q_PROPERTY on value

Q_PROPERTY(intvalue READ value WRITE setValue NOTIFY valueChanged)

 

you can do 

Label {
  text: "Value of cppObject: " +  cppObject.value
}
in QML, and
cppObject->value() in C++ to read it.
 
You could also do
 
someFunction: {
  cppObject.value = newData
}
 
in QML, and then in C, connect to the cppObject.valueChanged signal and do some stuff in your C++ code.
 
Does that make sense? I've run into a bunch of questions lately around people having trouble with QML and C++ integration, and if the docs are not helping I'd like to know what they are missing so we can fix it.
Paul Bernhardt
Application Development Consultant
BlackBerry
@PBernhardt

Did this answer your question? Please accept this post as the solution.
Found a bug? Report it to the Developer Issue Tracker
Contributor
Posts: 16
Registered: ‎05-30-2013
My Device: Z10, Q10
My Carrier: Rogers

Re: Camera from C++ to QML through foreign window

It makes perfectly sense, in fact having a Q_PROPERTY was my first approach. And using labels is really simple, but my real problem is the focus and there's no such control on imageView. Then I tried to make not one image changing but 3 images with the visible attribute using the CAMERA_FOCUSSTATE_SCENECHANGE but I needed one function to constantly keep track of this property and also a variable to check this in C++. 

I guess one of my biggest problems is the still poor understanding of how QML works, I mean, the loop cycles, interruptions, etc... Do you know can I implement this? Where to make the function in QML to make it always update this value?

 

And by the way, the docs are helping a lot, I made all the examples in that page. However, I think my case is more specific and that's why I cannot find my answer there.

 

Thank you for you time!