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
igosoft
Posts: 71
Registered: ‎09-19-2012
My Device: Z10 very soon

Re: Signals and Slots from a class.

Please attach all your source code and project files.

Contributor
somedeveloperguy
Posts: 34
Registered: ‎10-08-2012
My Device: developer

Re: Signals and Slots from a class.

i think you should try to derive your class from QObject and add the Q_OBJECT macro to the .h files.

as the page igosoft links to says: "All classes that contain signals or slots must mention Q_OBJECT at the top of their declaration. They must also derive (directly or indirectly) from QObject."

Super Contributor
JeffLemon
Posts: 440
Registered: ‎01-13-2011
My Device: Playbook

Re: Signals and Slots from a class.

[ Edited ]

Okay, so here is my component class:

 

Header:

 

#ifndef DRUMCOMPONENT_H_
#define DRUMCOMPONENT_H_

#include <bb/cascades/Application>
#include <QObject>

using namespace bb::cascades;

class DrumComponent: public QObject
{
    Q_OBJECT
	public:
    	explicit DrumComponent();
		void Test();

	signals:
	    void myFirstSignal();

};



#endif /* DRUMCOMPONENT_H_ */

 

 

 

#include "drumcomponent.h"

#include <bb/cascades/Application>
#include <QObject>

DrumComponent::DrumComponent()
{
}


void DrumComponent::Test()
{
	//EMIT THE SIGNAL
	emit myFirstSignal();

}

 It's still not working, am I missing something?

 

Im still getting the error:

 

no matching function for call to 'QObject::connect(DrumComponent*&, const char*, DrumKit* const, const char*)'

--------------------------------------------------------------------------------------------------
BlackBerry Apps: Instruments | ARTPAD | Piano | Drums | Xylophone
Contributor
somedeveloperguy
Posts: 34
Registered: ‎10-08-2012
My Device: developer

Re: Signals and Slots from a class.

i think DrumComponent.cpp also needs to have the code that says it includes QObject

like in my MainWidget.cpp it is

MainWidget::MainWidget(QWidget *parent) :
    QWidget(parent)

 and you have to do the same for the class containing the slot

Super Contributor
JeffLemon
Posts: 440
Registered: ‎01-13-2011
My Device: Playbook

Re: Signals and Slots from a class.

Thanks, it compiles now with no errors but it won't run, this comes up on the console:

 

PVR:smileysad:Warning): InitContext: ignoring buffer type CBUF_TYPE_PDS_VERT_SECONDARY_PREGEN_BUFFER [778, /eglglue.c]

--------------------------------------------------------------------------------------------------
BlackBerry Apps: Instruments | ARTPAD | Piano | Drums | Xylophone
Contributor
somedeveloperguy
Posts: 34
Registered: ‎10-08-2012
My Device: developer

Re: Signals and Slots from a class.

unfortunatly I don't know where that error comes from.

Developer
sporadicsoftware
Posts: 72
Registered: ‎09-30-2011
My Device: Bold 9930 & PlayBook

Re: Signals and Slots from a class.

If you are still doing this:

 

MyComponent *myComponent = new MyComponent();
bool res = QObject::connect(myComponent, SIGNAL(myFirstSignal()), this, SLOT(handleEmit()));

and:

MyComponent::MyComponent()
{
	//EMIT THE SIGNAL
	emit myFirstSignal();
}

 

 then the problem appears to be that the signal is emitted when the object is created but you don't connect to the signal until after the object is created.

Super Contributor
JeffLemon
Posts: 440
Registered: ‎01-13-2011
My Device: Playbook

Re: Signals and Slots from a class.

No I changed that to:

 

#include "drumcomponent.h"

#include <bb/cascades/Application>
#include <QObject>

DrumComponent::DrumComponent()
{
}


void DrumComponent::Test()
{
	//EMIT THE SIGNAL
	emit myFirstSignal();

}

 

I've been trying to find out where the error is and everything runs fine until I add back in:

 

bool res = QObject::connect(drumComponent, SIGNAL(myFirstSignal()), this, SLOT(handleEmit()));
	Q_ASSERT(res);
	Q_UNUSED(res);

 

--------------------------------------------------------------------------------------------------
BlackBerry Apps: Instruments | ARTPAD | Piano | Drums | Xylophone
Super Contributor
JeffLemon
Posts: 440
Registered: ‎01-13-2011
My Device: Playbook

Re: Signals and Slots from a class.

Got it, missed:

 

classDrumKit : publicQObject

{

Q_OBJECT

 

 

--------------------------------------------------------------------------------------------------
BlackBerry Apps: Instruments | ARTPAD | Piano | Drums | Xylophone