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
Regular Contributor
andreyavram
Posts: 76
Registered: ‎06-02-2012
My Device: Playbook, BB10

MediaKey

Hi,

 

Considering a webworks extension, and the following code:

 

MediaKeyWatcher* keyWatcher = new MediaKeyWatcher(MediaKey::VolumeUp);
bool success =QObject::connect(&keyWatcher, SIGNAL(longPress(bb::multimedia::MediaKey::Type)), this, SLOT(templateTestString()));

 

 

While compilling I receive the following error: "invalid use of 'this' at top", what should "this" refer to?

I wrote this code before line 27: in the standard extension example, found here: https://github.com/blackberry/WebWorks-Community-APIs/blob/master/BB10/Template/NDK_project/src/temp...  

 

Thanks

 

BlackBerry Development Advisor
MSohm
Posts: 14,753
Registered: ‎07-09-2008
My Device: BlackBerry Passport

Re: MediaKey

It should be after line 27 (which ends on line 34).  Before it it outside of any method, so "this" doesn't exist.

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Regular Contributor
andreyavram
Posts: 76
Registered: ‎06-02-2012
My Device: Playbook, BB10

Re: MediaKey

So I put the slot connect code inside a method like this:

std::string TemplateNDK::templateTestString() {
	//using namespace QObject;
	bool success = QObject::connect(&keyWatcher, SIGNAL(shortPress(bb::multimedia::MediaKey::Type)), this, SLOT(templateTestString()));
	return "works!";
}

 I included this in my header also:

#include <bb/multimedia/MediaKey>
#include <bb/multimedia/MediaKeyWatcher>
#include <bb/multimedia/MediaKeyNotification>
#include <QObject>

 

But I still receive an error "no matching function for call to 'QObject::connect(bb::multimedia::MediaKeyWatcher**, const char*, webworks::TemplateNDK* const, const char*)'"

 

I know it's something related to the namespace of QObject but I didn't find anything helpful on the internet.

I also know that this questions are more related to C++ development than Native SDK, but I would be really happy if anyone could assist me on this matter.

 

Thanks!

BlackBerry Development Advisor
MSohm
Posts: 14,753
Registered: ‎07-09-2008
My Device: BlackBerry Passport

Re: MediaKey

Can you show how you are creating keyWatcher?  Note that your code is going to trigger duplicates signals being received because you're connecting again every time the signal fires.

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Regular Contributor
andreyavram
Posts: 76
Registered: ‎06-02-2012
My Device: Playbook, BB10

Re: MediaKey

[ Edited ]

In the basic template example https://github.com/blackberry/WebWorks-Community-APIs/blob/master/BB10/Template/NDK_project/src/temp... on line 26 I create the keywatcher object and then I want to connect the signal to a custom method, and just to test it out, I pasted the connect code to another method, so I can call it at a certain point and see if it works.

 

What I'm trying to achieve should be a very simple task for a C++ developer, but for a JS developer it's not :smileyhappy:

 

 

namespace webworks {
...
MediaKeyWatcher* keyWatcher = new MediaKeyWatcher(MediaKey::VolumeUp);
....
BlackBerry Development Advisor
MSohm
Posts: 14,753
Registered: ‎07-09-2008
My Device: BlackBerry Passport

Re: MediaKey

Change &keyWatcher to keyWatcher and you should be all set.

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Regular Contributor
andreyavram
Posts: 76
Registered: ‎06-02-2012
My Device: Playbook, BB10

Re: MediaKey

I already tried that, but it doesn't to work, I receive the "no matching function for call to 'QObject::connect(bb::multimedia::MediaKeyWatcher*&, const char*, webworks::TemplateNDK* const, const char*)'" 

 

I quess the first parameter type is wrong, but I don't know what else to try at this point.

 

Here is the partial code right now:

 

#include <bb/multimedia/MediaKey>
#include <bb/multimedia/MediaKeyWatcher>
#include <bb/multimedia/MediaKeyNotification>
#include <QObject>



namespace webworks {

bb::multimedia::MediaKeyWatcher* keyWatcher = new bb::multimedia::MediaKeyWatcher(bb::multimedia::MediaKey::VolumeUp);

TemplateNDK::TemplateNDK(TemplateJS *parent) {
...

bps_initialize();
bool success = QObject::connect(keyWatcher, SIGNAL(shortPress(bb::multimedia::MediaKey::Type)), this, SLOT(templateTestString()));
}
...
}
....

 I checked if the QObject file is correctly linked, and it's correct.

 

Thanks a lot for your answers so far!

BlackBerry Development Advisor
MSohm
Posts: 14,753
Registered: ‎07-09-2008
My Device: BlackBerry Passport

Re: MediaKey

Have you also defined the slot in your header file?  Can you post it?

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Regular Contributor
andreyavram
Posts: 76
Registered: ‎06-02-2012
My Device: Playbook, BB10

Re: MediaKey

No, I haven't defined the slot in the header. That info was not on the MediaKey docs page.

Can you show me, please, how to do that?

BlackBerry Development Advisor
MSohm
Posts: 14,753
Registered: ‎07-09-2008
My Device: BlackBerry Passport

Re: MediaKey

In your header file you'll need something like this:

 

public slots:
     std::string void templateTestString();

 You can see some more examples here:

 

Signals and slots

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker