Does qmlregistertype, after usage in qml file, call the constructor of the c++ object? [SOLVED]
-
wrote on 10 Jun 2013, 07:48 last edited by
I was wondering about the behaviour of the registered type with the qml engine.
I am working in cascades qt so qt 4.8 ish.So I registered a type, with qmlregistertype.
Created the qml type in a qml document.When the Qml document is created there is no errors in the device log.
But the constructor for object do not appeared to be called at all.Does the Qml instanced object have its c++ counterpart constructor called on creation , or od I have or invoke it?
-
You need to use the type in your QML for the constructor to be called, although from your description I take it that that is what you have done. How are you checking whether the constructor was called?
-
wrote on 10 Jun 2013, 09:05 last edited by
I put a qDebug() << "The constructor was called"
Then I put a qDebug << "This function was called"
Okay debug output for device now works.
I have an issue though, it appears that it is calling my default constructor what I need it to call though is the overridden constructor.
The reason for this is, that I inherited the bb::cascades::multimedia::Camera.
To create own qml camera.and I have a constructor like so
myCamera::myCamera()
{
qDebug() << "HELLO I AM DONE DEFAULT ()!!!!";}
myCamera::myCamera(bb::cascades::Container* parent):
Camera(parent)
{
qDebug() << "HELLO I AM DONE OVERRIDEN()!!!!";}
It ends up calling the first constructor, and then my signals and slots will not connect ,even though they inherit public signals from the bb10 camera I just inherited.
I need a way to invoke the second constructor any clues?
-
Use C++11 if you dare. Older C++ standards do not allow calling constructors from within other constructors.
Or "distribute" your code a bit. For example, you can add a Q_INVOKABLE init() method and call it from QML in Component.onCompleted() to set your object up.
-
wrote on 10 Jun 2013, 09:17 last edited by
Yeah that does not work to well, I don't think its a good idea to inherit c++ cascades multimedia camera, object and expect it to reflect its self in qml ... is this correct?
because from what I can tell the qdeclarative parser only allows the default constructor to be called.
So this is what I have
bb10 camera -> myCamera
qmlregistertype<myCamera>connect signals and slots
@
connect(this,SIGNAL(this->touch(bb::cascades::TouchEvent*)),this,SLOT(OnTouch()));// Signaled when the rear of front cameras are opened.
connect(this->parent(),SIGNAL(this->parent->cameraOpened()),this,SLOT(OnCameraOpened()));// Signaled when a picture is taken.
connect(this,SIGNAL(this->shutterFired()),this,SLOT(OnShutterFired()));connect(this,SIGNAL(this->viewfinderStarted()),this,SLOT(OnViewFinderStarted()));
// Signaled when a picture is about to be saved.
connect(this,SIGNAL(this->photoSaved(const QString &, quint64)),this,SLOT(OnPhotoSaved()));
qDebug() << "HELLO I AM DONE CONNECTING!!!!";
@Then the debug output messages say that there are no corresponding signals.
A better path of design I guess would to be compose the camera object in this class and wrap some of the functions of the camera to my own MyCamera class?
I am just wondering what the best practice is, from all the code examples I have seen on the bb10 sdk site they are just horrible
-
Please wrap that code in '@' tags, it's difficult to read.
-
wrote on 10 Jun 2013, 09:25 last edited by
Sorry I forgot about that haha
-
That line looks wrong:
@
connect(this->parent(),SIGNAL(this->parent->cameraOpened()),this,SLOT(OnCameraOpened()));
@Should be SIGNAL(cameraOpened()). Also, all remaining statements connect this and not parent, so I'm a bit confused.
-
wrote on 10 Jun 2013, 09:31 last edited by
@
qDebug() << "HELLO I AM CONNECTING!!!!";
// These are private slots that is they are used internally for camera functionality.
// These functions should not really be exposed to Qml for use in the Qml interface.// Connecting the inherited signal touch event to that of the non implicit onTouched.
// Since we do not have a capture camera button touching the surface will result in a
// captureconnect(this,SIGNAL(touch(bb::cascades::TouchEvent*)),this,SLOT(OnTouch()));
// Signaled when the rear of front cameras are opened.
connect(this,SIGNAL(cameraOpened()),this,SLOT(OnCameraOpened()));// Signaled when a picture is taken.
connect(this,SIGNAL(shutterFired()),this,SLOT(OnShutterFired()));connect(this,SIGNAL(viewfinderStarted()),this,SLOT(OnViewFinderStarted()));
// Signaled when a picture is about to be saved.
connect(this,SIGNAL(photoSaved(const QString &, quint64)),this,SLOT(OnPhotoSaved()));
qDebug() << "HELLO I AM DONE CONNECTING!!!!";
@Okay I have fixed it to be this since I made a mistake.
I had assumed that if I passed this (Camera) I would have to refer to its function using the this pointer.So that log error warning went away.
and Camera actually functions now.
Thanks I think this should be resolved now =)
-
I'm glad to hear that! Happy coding!
Please add "[Solved]" to thread's title (you need to edit your initial post) if you have a spare minute.
7/10