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


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
Developer
Posts: 17,025
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany
Accepted Solution

Problems with the barcode reader sample

I want to integrate barcode scanning in my app, but it seems to be much more complicated than i thought.

 

I am using the BarcodeReader sample, and when i integrate its code 1:1 it works properly.

As soon as I try to change it, however, it does not.

 

I would like to:

- use it without a cover and an animation

- have it all in a sheet with a close button instead of a page

 

When i place "camera.open()" in onCreationCompleted, for example, the camera opens as desired, but the barcode scanner does not do anything.

I have also tried to launch the camera delayed (by 200 or 400ms) using QTimer::singleShot in c++, the camera opens but still no barcode scanning.

 

A comment in the sample code indicates "Work around a bug temporarily", any idea if that could be related?

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 1,524
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: Problems with the barcode reader sample

This class is very buggy. You'll have to do the initialization twice, the second one after a ~200 ms delay after the first one. That's what the sample is doing.

 

I was able to make it work with single initialization by setting the camera right after creating barcode detector:

camera_ = new Camera();
barcodeDetector_ = new BarcodeDetector(this);
barcodeDetector_->setCamera(camera_);

But if I modify any properties of the camera (such as viewfinder size) during the initialization or in viewfinderStarted() signal handler, it stops working and double-initialization hack has to be used to make it work.

 


Andrey Fidrya, @zmeyc on twitter
Developer
Posts: 17,025
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Problems with the barcode reader sample

That sounds like it would resolve the issue, but it seems i am still doing something wrong.

 

Here is what I currently do:

onCreationCompleted: {
    util.launchCamera(camera);
}

 

void Util::launchCamera(QObject* object) {
	qDebug() << "inside launchCamera";
	Camera* camera = dynamic_cast<Camera*>(object);
	if (camera){
		camera->open();
		QTimer::singleShot(400, camera, SLOT(open()));
	} else {
		qDebug() << "no camera";
	}
}

 

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 1,524
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: Problems with the barcode reader sample

[ Edited ]

Make sure that camera.startViewfinder() is called in onCameraOpened, and the camera is assigned to barcodeDetector on creation or in onViewfinderStarted.

Also try using a custom slot and calling camera->open() by hand from there. Open() slot has one argument with default value. There's a chance that direct connection won't work as QTimer's signal is not passing any arguments to it.

 

If it still doesn't work, try setting a larger timeout, for example 2000 msec.

 


Andrey Fidrya, @zmeyc on twitter
Developer
Posts: 17,025
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Problems with the barcode reader sample

[ Edited ]

it works!
I have to use a longer delay to call the second open slot, will have to experiement a bit to find a good value now.

edit: 800ms seem to work, 700 do not.

That was a real pain to develop, took me a lot longer than expected. Next time i'll post quicker, but i suspected some errors on my side.

 

edit:

I still wonder why it does not work when i put it into a sheet.

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Retired
Posts: 749
Registered: ‎12-16-2008
My Device: BlackBerry Z30
My Carrier: Bell

Re: Problems with the barcode reader sample

So you are calling open twice? Are you not getting a cameraOpened signal? 

 

Actually assigning the camera to the barcode detector should not happen until the viewfinderStarted signal has been fired. That could be why delaying is working for you.

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
Developer
Posts: 1,524
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: Problems with the barcode reader sample

cameraOpened signal is fired and I've tried assigning the camera to barcode detector in viewfinderStarted slot, but the detection is not working unless camera.open is called twice.

This is easily reproduced by commenting out the first open() call in BarcodeReader sample.


Strangely, it works if the barcode detector is assigned right after creating the camera, but if any of the camera settings are changed it stops working.

Andrey Fidrya, @zmeyc on twitter
Developer
Posts: 17,025
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Problems with the barcode reader sample

My observations match those of Zmey. If you check the sourcecode of the sample you'll find a comment that mentions "a bug". It would be nice to write a line or two more about it, at least until it is fixed.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Highlighted
Developer
Posts: 412
Registered: ‎04-04-2012
My Device: BlackBerry Z30/Z10/Z10LE/Q10/PlayBook

Re: Problems with the barcode reader sample

Yes. This needs to be fixed ASAP.

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

Re: Problems with the barcode reader sample

Interesting. If you create a DIT issue, I will find the bug mentioned in the source code and link them together so you get notifed when it gets fixed. I'll also ask the sample team to add more elaboration.

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