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
apascual
Posts: 26
Registered: ‎07-23-2012
My Device: bb10 dev alpha

Camera, initial code help

Hello again ppl!

 

I have an application with database and want to implement a camera button on one of my QML. I've looked at the code photobomberapp, when loading the application executes this:

 

PhotoBomberApp::PhotoBomberApp() {
	Camera::registerQmlTypes();

	QmlDocument *qml = QmlDocument::create().load("main.qml");
	qml->setContextProperty("photoBomber", this);

	if (!qml->hasErrors()) {

		Page *appPage = qml->createRootNode<Page>();

		if (appPage) {

			Application::instance()->setScene(appPage);

			Camera *camera = appPage->findChild<Camera*>("myCamera");
			QObject::connect(camera, SIGNAL(shutterFired()), this,
					SLOT(onShutterFired()));

			camera->open(CameraUnit::Rear);
			camera->startViewfinder();
		}
	}
}

 All clear here, but the question is:

 

How i can run that code without being the principal code at app start?

 

Thank you again! :smileyhappy:

Please use plain text.
BlackBerry Development Advisor (Retired)
mgoulet
Posts: 329
Registered: ‎05-07-2012
My Device: BB Alpha

Re: Camera, initial code help

Hi there,

 

To make sure I understand correctly,which portion of this app do you want to delay further into the application? The camera setup code ,showing the camera feed or 'taking a picture' part?

 

Martin

 

Please use plain text.
Contributor
apascual
Posts: 26
Registered: ‎07-23-2012
My Device: bb10 dev alpha

Re: Camera, initial code help

Hi, thanks for reply! I want the camera setup code.

 

In my QML code I did:

 

ActionItem {
            title: "Camera"
            imageSource: "asset:///images/Edit.png"
            onTriggered: {
                _navPane.onCamera();
               
            }
        }

 call this function:

 

void App::onCamera() {
	Camera::registerQmlTypes();

	QmlDocument *qml = QmlDocument::create().load("camera/main.qml");
	qml->setContextProperty("photo", this);

	if (!qml->hasErrors()) {

		Page *appPage = qml->createRootNode<Page>();

		if (appPage) {

			Application::instance()->setScene(appPage);

			Camera *camera = appPage->findChild<Camera*>("myCamera");
			QObject::connect(camera, SIGNAL(shutterFired()), this,
					SLOT(onShutterFired()));

			camera->open(CameraUnit::Rear);
			camera->startViewfinder();
		}
	}
}

Sometimes in the "first run" after "Run" the application all works and i can see the camera. After this, when i click the ActionItem buttun it freezes the application and say:

 

application did not hanfle 'exit' message and was slayed

 

### BAD_FRAME pid=21250255 at 181224307 ms -> t: 21 ms p1: 0 ms, r: 14 ms, p2: 0 ms, u: 7 ms
CameraPrivate::smileysurprised:pen
CamCommandQueue::AddCommand: queue count(1), cmd(1)
CamControllerInternal::ExecuteCommand OPEN=1
CamControllerInternal:smileysurprised:pen api version (2)
CamControllerInternal:smileysurprised:pen(2) success
CamControllerInternal::ExecuteCommand OPEN = result (0)
CameraPrivate::startViewfinder
CamCommandQueue::AddCommand: queue count(1), cmd(4)

 

 

 

One thing more, when I do this CapturePhoto does nothing

 

id: camera
                objectName: "myCamera"
                onTouch: {
                    if (event.isDown()) {
                        capturePhoto();
                        setting.visible = true;
                    }
                } 

 

file:///accounts/1000/appdata/com.example.Myapp.testDev_ample_Myappde1f94c3/app/native/assets/camera/main.qml:21: ReferenceError: Can't find variable: setting

 

 

Thank you for all! :smileyhappy:

Please use plain text.
Developer
ekke
Posts: 1,544
Registered: ‎04-08-2010
My Device: Z10 (red Limited Edition), Q10, Z30
My Carrier: Telekom.de, O2, Vodafone

Re: Camera, initial code help

Hi Apascual,

 

please take a look at CameraCapturePage plus corresponding code at opendataspace.cpp

https://github.com/blackberry/opendataspace-cascades

 

I'm opening the Camera inside QML

 

there are some issues (reported, but not yet public, will let you know as soon as my issues are public)

- using REAR camery I'm running into problems (Issue BBTEN-250 and also using Landscape I'm running into problems BBTEN-249)

 

ekke

-------------------------------------------------------------------------------
ekke (independent software architect, rosenheim, germany)

BlackBerry Elite Developer
BlackBerry Platinum Enterprise Partner
International Development Mobile Apps BlackBerry 10 Cascades
Cascades - Workshops / Trainings / Bootcamps

blog: http://ekkes-corner.org videos: http://www.youtube.com/user/ekkescorner http://vimeo.com/ekkescorner/videos
bb10-development: http://appbus.org Twitter: @ekkescorner
Please use plain text.
Contributor
apascual
Posts: 26
Registered: ‎07-23-2012
My Device: bb10 dev alpha

Re: Camera, initial code help

Hello ekke, thanks for reply

 

I looked at your camera code and have more or less the same. Continuous freezing the application when clicking on my camera button.

 

I'm "frozen" for now :smileyhappy:

 

Thanks!

Please use plain text.