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
Developer
javoid
Posts: 194
Registered: ‎11-24-2012
My Device: Dev Alpha B, Bold 9700

How to add a camera without QML file?

[ Edited ]

All the samples I've seen do this:

 

Camera *camera = root->findChild<Camera*>("myCamera");

I've sucessfully added a camera in straight C.

 

Now I would like to do so with cascades, but I'm thinking it doesn't need a QML file.

 

For example, I can declare a button like so:

Button *button; 

Then in the implementation:

button = new Button():

...and add it to an existing container.

 

I'd like to add a camera created in code to my existing container:

Camera *camera = new Camera();
myContainer->add(myCamera);

 But this doesn't work.  I get an error for:

undefined reference to bb::cascades::multimedia::Camera::Camera(bb::cascades::Container*)

 

I tried to pass in a reference to an existing container that it will be contained in, but I get mor errors.

 

All the demos I found on github (including the jam source codes) all show either straight C or QML.  I know I can make a QML file, but I'm trying to do this purely in C++.

 

Am I wrong about this?  Does creating an instance of Camera in cascades require a QML file?

 

 

 

Developer
javoid
Posts: 194
Registered: ‎11-24-2012
My Device: Dev Alpha B, Bold 9700

Re: How to add a camera without QML file?

Can anyone help?   :Helpsmilie:

 

I've banging my head with this for the past 2 days. 

Developer
BGmot
Posts: 1,068
Registered: ‎11-24-2011
My Device: PlayBook

Re: How to add a camera without QML file?

can you provide full console output when you are building your app?

Developer
javoid
Posts: 194
Registered: ‎11-24-2012
My Device: Dev Alpha B, Bold 9700

Re: How to add a camera without QML file?

[ Edited ]

Sure thing!

 

Here's the code:

 

H file:

 

#ifndef CAMERACONTOLLER_H_
#define CAMERACONTOLLER_H_

#include <QtCore/QObject>
#include <QtCore/QMetaType>

#include <bb/cascades/Application>
#include <bb/cascades/multimedia/Camera>

using namespace bb::cascades;
using namespace bb::cascades::multimedia;

class CameraContoller : public QObject
{
	Q_OBJECT

public:
	CameraContoller();
	~CameraContoller();

	Container* getCameraContainer();

	void startCamera();
	void stopCamera();

private:
	Container *m_cameraContainer;
	Camera *m_camera;
};

#endif /* CAMERACONTOLLER_H_ */

 cpp file:

#include <bb/cascades/multimedia/Camera>
#include <bb/cascades/multimedia/CameraUnit>
#include <bb/cascades/multimedia/CameraSettings>
#include <bb/cascades/multimedia/CameraFlashMode>

using namespace bb::cascades;
using namespace bb::cascades::multimedia;

CameraContoller::CameraContoller()
{
	qmlRegisterType<Camera>("bb.cascades.multimedia",1,0,"Camera");

	m_cameraContainer = Container::create()
	        .layout(DockLayout::create())
	        .add(Container::create()
	            .horizontal(HorizontalAlignment::Center)
	            .vertical(VerticalAlignment::Center));

	m_camera = new Camera(m_cameraContainer);
	//m_camera = new Camera();
	m_cameraContainer->add(m_camera);
}

void CameraContoller::startCamera()
{
	m_camera->setPreferredWidth(768);
	m_camera->setPreferredHeight(1280);
	m_camera->open(CameraUnit::Rear);

	CameraSettings* cameraSettings = new CameraSettings();
	cameraSettings->setFlashMode(CameraFlashMode::Light);
	m_camera->applySettings(cameraSettings);

	m_camera->startViewfinder();
}

 Problem output:

 
Description Resource Path Location Type
make: *** [Device-Debug] Error 2 TestLed C/C++ Problem
make[1]: *** [debug] Error 2 TestLed C/C++ Problem
make[2]: *** [o.le-v7-g/TestLed] Error 1 TestLed C/C++ Problem
undefined reference to `bb::cascades::multimedia::Camera::~Camera()' TestLed line 86, external location: /Users/user/Applications/blackberry/target_10_0_9_1673/qnx6/usr/include/qt4/QtDeclarative/qdeclarativeprivate.h C/C++ Problem
undefined reference to `bb::cascades::multimedia::Camera::applySettings(bb::cascades::multimedia::CameraSettings*)' CameraContoller.cpp /TestLed/src line 176 C/C++ Problem
undefined reference to `bb::cascades::multimedia::Camera::Camera(bb::cascades::Container*)' CameraContoller.cpp /TestLed/src line 77 C/C++ Problem
undefined reference to `bb::cascades::multimedia::Camera::Camera(bb::cascades::Container*)' TestLed line 82, external location: /Users/user/Applications/blackberry/target_10_0_9_1673/qnx6/usr/include/qt4/QtDeclarative/qdeclarativeprivate.h C/C++ Problem
undefined reference to `bb::cascades::multimedia::Camera::smileysurprised:pen(bb::cascades::multimedia::CameraUnit::Type)' CameraContoller.cpp /TestLed/src line 172 C/C++ Problem
undefined reference to `bb::cascades::multimedia::Camera::startViewfinder()' CameraContoller.cpp /TestLed/src line 178 C/C++ Problem
undefined reference to `bb::cascades::multimedia::Camera::staticMetaObject' TestLed line 163, external location: /Users/user/Applications/blackberry/target_10_0_9_1673/qnx6/usr/include/qt4/QtDeclarative/qdeclarative.h C/C++ Problem
undefined reference to `bb::cascades::multimedia::Camera::staticMetaObject' TestLed line 189, external location: /Users/user/Applications/blackberry/target_10_0_9_1673/qnx6/usr/include/qt4/QtDeclarative/qdeclarative.h C/C++ Problem
undefined reference to `bb::cascades::multimedia::CameraSettings::CameraSettings(QObject*)' CameraContoller.cpp /TestLed/src line 174 C/C++ Problem
undefined reference to `bb::cascades::multimedia::CameraSettings::setFlashMode(bb::cascades::multimedia::CameraFlashMode::Type)' CameraContoller.cpp /TestLed/src line 175 C/C++ Problem
Source file of asset "TestLed.so" does not exist. bar-descriptor.xml /TestLed line 74 BlackBerry App Manifest Problem
Source file of asset "TestLed" does not exist. bar-descriptor.xml /TestLed line 69 BlackBerry App Manifest Problem
Source file of asset "TestLed" does not exist. bar-descriptor.xml /TestLed line 78 BlackBerry App Manifest Problem
Source file of asset "TestLed" does not exist. bar-descriptor.xml /TestLed line 82 BlackBerry App Manifest Problem

 

And console output:

 

**** Build of configuration Device-Debug for project TestLed ****
 
make Device-Debug 
make -C .//translations -f Makefile update
make[1]: Entering directory `/Users/user/Documents/code/blackberry/ndk-10.0.9-workspace/TestLed/translations'
/Users/user/Applications/blackberry/host_10_0_9_404/darwin/x86/usr/bin/lupdate TestLed.pro
Updating 'TestLed.ts'...
    Found 0 source text(s) (0 new and 0 already existing)
make[1]: Leaving directory `/Users/user/Documents/code/blackberry/ndk-10.0.9-workspace/TestLed/translations'
make -C .//translations -f Makefile release
make[1]: Entering directory `/Users/user/Documents/code/blackberry/ndk-10.0.9-workspace/TestLed/translations'
/Users/user/Applications/blackberry/host_10_0_9_404/darwin/x86/usr/bin/lrelease TestLed.pro
Updating '/Users/user/Documents/code/blackberry/ndk-10.0.9-workspace/TestLed/translations/TestLed.qm'...
    Generated 0 translation(s) (0 finished and 0 unfinished)
make[1]: Leaving directory `/Users/user/Documents/code/blackberry/ndk-10.0.9-workspace/TestLed/translations'
make -C ./arm -f Makefile debug
make[1]: Entering directory `/Users/user/Documents/code/blackberry/ndk-10.0.9-workspace/TestLed/arm'
make -f Makefile.Debug
make[2]: Entering directory `/Users/user/Documents/code/blackberry/ndk-10.0.9-workspace/TestLed/arm'
qcc -Vgcc_ntoarmv7le -c -Wc,-include -Wc,o.le-v7-g/.obj/TestLed -Wno-psabi -lang-c++ -fstack-protector-strong -mcpu=cortex-a9 -g -Wno-psabi -Wall -W -D_REENTRANT -DQT_NO_IMPORT_QT47_QML -DQ_OS_BLACKBERRY -DQT_DECLARATIVE_DEBUG -DQT_DECLARATIVE_LIB -DQT_CORE_LIB -DQT_SHARED -I/Users/user/Applications/blackberry/target_10_0_9_1673/qnx6/usr/share/qt4/mkspecs/blackberry-armv7le-qcc -I../../TestLed -I/Users/user/Applications/blackberry/target_10_0_9_1673/qnx6/usr/include/qt4/QtCore -I/Users/user/Applications/blackberry/target_10_0_9_1673/qnx6/usr/include/qt4/QtDeclarative -I/Users/user/Applications/blackberry/target_10_0_9_1673/qnx6/usr/include/qt4 -I../src -Io.le-v7-g/.moc -I/Users/user/Applications/blackberry/target_10_0_9_1673/qnx6/usr/include -I/Users/user/Applications/blackberry/target_10_0_9_1673/qnx6/usr/include/freetype2 -I. -o o.le-v7-g/.obj/CameraContoller.o ../src/CameraContoller.cpp
qcc -Vgcc_ntoarmv7le -lang-c++ -Wl,-rpath-link,/Users/user/Applications/blackberry/target_10_0_9_1673/qnx6/armle-v7/lib -Wl,-rpath-link,/Users/user/Applications/blackberry/target_10_0_9_1673/qnx6/armle-v7/usr/lib -Wl,-rpath-link,/Users/user/Applications/blackberry/target_10_0_9_1673/qnx6/armle-v7/usr/lib/qt4/lib -o o.le-v7-g/TestLed o.le-v7-g/.obj/CameraContoller.o o.le-v7-g/.obj/TestLed.o o.le-v7-g/.obj/main.o o.le-v7-g/.obj/moc_CameraContoller.o o.le-v7-g/.obj/moc_TestLed.o    -L/Users/user/Applications/blackberry/target_10_0_9_1673/qnx6/armle-v7/lib -L/Users/user/Applications/blackberry/target_10_0_9_1673/qnx6/armle-v7/usr/lib -L/Users/user/Applications/blackberry/target_10_0_9_1673/qnx6/armle-v7/usr/lib/qt4/lib -L/Users/user/Applications/blackberry/target_10_0_9_1673/qnx6//usr/lib/qt4/lib -lcamapi -lscreen -lbbcascades -lQtDeclarative -lQtScript -lQtSvg -lQtSql -lsqlite3 -lz -lQtXmlPatterns -lQtGui -lQtNetwork -lsocket -lQtCore -lm -lbps 
o.le-v7-g/.obj/CameraContoller.o: In function `CameraContoller':
make[2]: Leaving directory `/Users/user/Documents/code/blackberry/ndk-10.0.9-workspace/TestLed/arm'
make[1]: Leaving directory `/Users/user/Documents/code/blackberry/ndk-10.0.9-workspace/TestLed/arm'
 :Eek: errors start here
/Users/user/Documents/code/blackberry/ndk-10.0.9-workspace/TestLed/arm/../src/CameraContoller.cpp:80: undefined reference to `bb::cascades::multimedia::Camera::Camera(bb::cascades::Container*)'
o.le-v7-g/.obj/CameraContoller.o: In function `CameraContoller::startCamera()':
/Users/user/Documents/code/blackberry/ndk-10.0.9-workspace/TestLed/arm/../src/CameraContoller.cpp:175: undefined reference to `bb::cascades::multimedia::Camera::smileysurprised:pen(bb::cascades::multimedia::CameraUnit::Type)'
/Users/user/Documents/code/blackberry/ndk-10.0.9-workspace/TestLed/arm/../src/CameraContoller.cpp:177: undefined reference to `bb::cascades::multimedia::CameraSettings::CameraSettings(QObject*)'
/Users/user/Documents/code/blackberry/ndk-10.0.9-workspace/TestLed/arm/../src/CameraContoller.cpp:178: undefined reference to `bb::cascades::multimedia::CameraSettings::setFlashMode(bb::cascades::multimedia::CameraFlashMode::Type)'
/Users/user/Documents/code/blackberry/ndk-10.0.9-workspace/TestLed/arm/../src/CameraContoller.cpp:179: undefined reference to `bb::cascades::multimedia::Camera::applySettings(bb::cascades::multimedia::CameraSettings*)'
/Users/user/Documents/code/blackberry/ndk-10.0.9-workspace/TestLed/arm/../src/CameraContoller.cpp:181: undefined reference to `bb::cascades::multimedia::Camera::startViewfinder()'
o.le-v7-g/.obj/CameraContoller.o: In function `int qmlRegisterType<bb::cascades::multimedia::Camera>(char const*, int, int, char const*)':
/Users/user/Applications/blackberry/target_10_0_9_1673/qnx6/usr/include/qt4/QtDeclarative/qdeclarative.h:163: undefined reference to `bb::cascades::multimedia::Camera::staticMetaObject'
/Users/user/Applications/blackberry/target_10_0_9_1673/qnx6/usr/include/qt4/QtDeclarative/qdeclarative.h:163: undefined reference to `bb::cascades::multimedia::Camera::staticMetaObject'
/Users/user/Applications/blackberry/target_10_0_9_1673/qnx6/usr/include/qt4/QtDeclarative/qdeclarative.h:189: undefined reference to `bb::cascades::multimedia::Camera::staticMetaObject'
/Users/user/Applications/blackberry/target_10_0_9_1673/qnx6/usr/include/qt4/QtDeclarative/qdeclarative.h:189: undefined reference to `bb::cascades::multimedia::Camera::staticMetaObject'
o.le-v7-g/.obj/CameraContoller.o: In function `QDeclarativeElement':
/Users/user/Applications/blackberry/target_10_0_9_1673/qnx6/usr/include/qt4/QtDeclarative/qdeclarativeprivate.h:82: undefined reference to `bb::cascades::multimedia::Camera::Camera(bb::cascades::Container*)'
o.le-v7-g/.obj/CameraContoller.o:smileysad:.rodata._ZTVN19QDeclarativePrivate19QDeclarativeElementIN2bb8cascades10multimedia6CameraEEE[_ZTVN19QDeclarativePrivate19QDeclarativeElementIN2bb8cascades10multimedia6CameraEEE]+0x8): undefined reference to `bb::cascades::multimedia::Camera::metaObject() const'
o.le-v7-g/.obj/CameraContoller.o:smileysad:.rodata._ZTVN19QDeclarativePrivate19QDeclarativeElementIN2bb8cascades10multimedia6CameraEEE[_ZTVN19QDeclarativePrivate19QDeclarativeElementIN2bb8cascades10multimedia6CameraEEE]+0xc): undefined reference to `bb::cascades::multimedia::Camera::qt_metacast(char const*)'
o.le-v7-g/.obj/CameraContoller.o:smileysad:.rodata._ZTVN19QDeclarativePrivate19QDeclarativeElementIN2bb8cascades10multimedia6CameraEEE[_ZTVN19QDeclarativePrivate19QDeclarativeElementIN2bb8cascades10multimedia6CameraEEE]+0x10): undefined reference to `bb::cascades::multimedia::Camera::qt_metacall(QMetaObject::Call, int, void**)'
o.le-v7-g/.obj/CameraContoller.o:smileysad:.rodata._ZTIN19QDeclarativePrivate19QDeclarativeElementIN2bb8cascades10multimedia6CameraEEE[_ZTIN19QDeclarativePrivate19QDeclarativeElementIN2bb8cascades10multimedia6CameraEEE]+0x8): undefined reference to `typeinfo for bb::cascades::multimedia::Camera'
o.le-v7-g/.obj/CameraContoller.o: In function `~QDeclarativeElement':
/Users/user/Applications/blackberry/target_10_0_9_1673/qnx6/usr/include/qt4/QtDeclarative/qdeclarativeprivate.h:86: undefined reference to `bb::cascades::multimedia::Camera::~Camera()'
/Users/user/Applications/blackberry/target_10_0_9_1673/qnx6/usr/include/qt4/QtDeclarative/qdeclarativeprivate.h:86: undefined reference to `bb::cascades::multimedia::Camera::~Camera()'
cc: /Users/user/Applications/blackberry/host_10_0_9_404/darwin/x86/usr/bin/ntoarm-ld error 1
make[2]: *** [o.le-v7-g/TestLed] Error 1
make[1]: *** [debug] Error 2
make: *** [Device-Debug] Error 2
 
**** Build Finished ****
Developer
javoid
Posts: 194
Registered: ‎11-24-2012
My Device: Dev Alpha B, Bold 9700

Re: How to add a camera without QML file?

I'm also including the bb/cascades/container and a few others in the cpp file, but it's not shown in the trimmed files above.

 

 

Developer
BGmot
Posts: 1,068
Registered: ‎11-24-2011
My Device: PlayBook

Re: How to add a camera without QML file?

It's linker's error so nothing to do with #include's. Indeed it can't find symbols although you seem to include all needed libraries. Couple of questions:

1. Why do you need all these QtXxx libraries??

>lQtDeclarative -lQtScript -lQtSvg -lQtSql -lsqlite3 -lz -lQtXmlPatterns -lQtGui -lQtNetwork -lsocket -lQtCore -lm -lbps 

2. What's the purpose of 

>qmlRegisterType<Camera>("bb.cascades.multimedia",1,0,"Camera");

you said you didn't want to use QML...

Developer
javoid
Posts: 194
Registered: ‎11-24-2012
My Device: Dev Alpha B, Bold 9700

Re: How to add a camera without QML file?

"1. Why do you need all these QtXxx libraries??"

 

I have been butchering my code trying to figure out what works and what doesn't.  I also started from a sample project so they may have been included then.

 

"2. What's the purpose of 

>qmlRegisterType<Camera>("bb.cascades.multimedia",1,0,"Camera");"

 

I read somewhere that there would be a problem without it (I added it when I was butchering the code).

 

"It's linker's error so nothing to do with #include's"

 

Okay, so what do you recommend?

 

Developer
javoid
Posts: 194
Registered: ‎11-24-2012
My Device: Dev Alpha B, Bold 9700

Re: How to add a camera without QML file?

">lQtDeclarative -lQtScript -lQtSvg -lQtSql -lsqlite3 -lz -lQtXmlPatterns -lQtGui -lQtNetwork -lsocket -lQtCore -lm -lbps "

 

I've looked all over the project and can't see where these are being added.

 

 

Developer
javoid
Posts: 194
Registered: ‎11-24-2012
My Device: Dev Alpha B, Bold 9700

Re: How to add a camera without QML file?

When creating a default Cascades project, those libs are added automatically to my build.

BlackBerry Development Advisor
smcveigh
Posts: 668
Registered: ‎11-29-2011
My Device: developer

Re: How to add a camera without QML file?

there is more or less a working bare-bones cascades C++ camera example in this thread:

 

http://supportforums.blackberry.com/t5/Cascades-Development/set-aspect-ratio-for-the-Camera-custom-c...