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

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! Smiley Happy

Retired
Posts: 329
Registered: ‎05-07-2012
My Device: BB Alpha
My Carrier: N/A

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

 

Contributor
Posts: 26
Registered: ‎07-23-2012
My Device: bb10 dev alpha
My Carrier: movistar

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:Smiley Surprisedpen
CamCommandQueue::AddCommand: queue count(1), cmd(1)
CamControllerInternal::ExecuteCommand OPEN=1
CamControllerInternalSmiley Surprisedpen api version (2)
CamControllerInternalSmiley Surprisedpen(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! Smiley Happy

Developer
Posts: 1,746
Registered: ‎04-08-2010
My Device: Passport Silver, PRIV
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 native Mobile Business Apps
BlackBerry 10 | Qt Mobile (Android, iOS)
Workshops / Trainings / Bootcamps

blog: http://ekkes-corner.org
mobile-development: http://appbus.org Twitter: @ekkescorner
Highlighted
Contributor
Posts: 26
Registered: ‎07-23-2012
My Device: bb10 dev alpha
My Carrier: movistar

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 Smiley Happy

 

Thanks!