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
slashkyle
Posts: 820
Registered: ‎10-16-2012
My Device: Red Z10

Screen Events

[ Edited ]

in my previous post I came to the realization that I need to interact with screen events from C++ 

moving this to a new thread because it's not related to the keyboard....

 

I'm trying to interact with the entire screen (bezel & all) however this doesnt seem to be possible from QML

Im currently using the BPS Monitor & discovered this Multi-touch Handler

 

I belive that i've managed to get it working with the bps monitor but to test it

 

my issue is, trying to get a qml label to update with the current X, Y positions

 

//in appname.cpp

AbstractPane *root = qml->createRootObject<AbstractPane>();
    Label *mLabel = root->findChild<Label*>("rootLabel");
    mLabel->setText("C++ Label");

 I'm able to change the text of the qml label but I do not know how to access the child object in my ScreenService.cpp file, currently its accessed in appName.cpp

 

case SCREEN_EVENT_MTOUCH_TOUCH:

		if (!found) {

			Touchpoint *tp = new Touchpoint(mtouch_event.x, mtouch_event.y,
					mtouch_event.contact_id);
			if(mtouch_event.contact_id<4){
				//interact with touch events here
				// such as mLabel->setText("X " + mtouch_event.x + ", Y " + mtouch_event.y);
			}
Developer
Zmey
Posts: 1,512
Registered: ‎12-18-2012
My Device: PlayBook, Z10, DAC

Re: Screen Events

Hi,

You can do something like this in any object:

Label *s = Application::instance()->scene()->findChild<Label *>(
"rootLabel");

From the encapsulation point of view it's better to emit the signal with coordinates from child object and subscribe to this signal in interface class and update the label there.

Andrey Fidrya, @zmeyc on twitter
Developer
slashkyle
Posts: 820
Registered: ‎10-16-2012
My Device: Red Z10

Re: Screen Events

doing that in screenService.cpp tells me that application is not declared....

 

It would probably be easier if i linked the X & Y values from screenService & update the label with them later but I still have no idea how to do such a thing using c++, once i want to leave the current page with a value, nothing wants to work :smileysad:

 

i do have access to touchpoint.cpp/h , it has a value of Touchpoint::getX & getY which would return the values to me if it ever decides to cooperate

 

 

Developer
Zmey
Posts: 1,512
Registered: ‎12-18-2012
My Device: PlayBook, Z10, DAC

Re: Screen Events

[ Edited ]

Add these lines to screenService.cpp:

#include <bb/cascades/Application>
using namespace bb::cascades;

 

Regarding the second approach:

 

Declare a signal in ScreenService header:

 

signals:
  void positionUpdated(int x, int y);

 

Emit the signal when position updates:

 

emit positionUpdated(newX, newY);

Now any other class can subscribe to this signal. 

 

Declare a slot in class which instantiates ScreenService:

public slots:
  void onPositionUpdated(int x, int y);

After creating ScreenServer instance connect it's signal to the slot:

QObject::connect(screenServer, SIGNAL(positionUpdated(int,int)),
this, SLOT(onPositionUpdated(int,int)));

In onPositionUpdated handler update the label.

 


Andrey Fidrya, @zmeyc on twitter
Developer
slashkyle
Posts: 820
Registered: ‎10-16-2012
My Device: Red Z10

Re: Screen Events

thanks for the fast response, that light everything up as if it should work but when i go to build it tells me 

 

invalid use of incomplete type 'struct bb::cascades::AbstractPane'

Developer
Zmey
Posts: 1,512
Registered: ‎12-18-2012
My Device: PlayBook, Z10, DAC

Re: Screen Events

[ Edited ]

Include all incomplete types in .cpp file as well:
#include <bb/cascades/AbstractPane>
etc

 

Updated my previous answer with more details on signal/slot approach.

 


Andrey Fidrya, @zmeyc on twitter
Developer
slashkyle
Posts: 820
Registered: ‎10-16-2012
My Device: Red Z10

Re: Screen Events

[ Edited ]

Thanks again for the help, i've nearly figured it out & sorry to be a plague c++ is not my friend

 

it's saying newX & Y don't exist so

emit positionUpdated(newX, newY);

 if i replace it with this which is setup to values set touchpoint.cpp

emit positionUpdated(mtouch_event.x, mtouch_event.y);

 

it gives me no errors (or visible results) when i build this

void ScreenService::onPositionUpdated(int x, int y){
	QString xstring = QString::number(x);
	QString ystring = QString::number(y);
	Label *s = Application::instance()->scene()->findChild<Label *>(
	"rootLabel");
	QObject::connect(s, SIGNAL(positionUpdated(int,int)),
	  this, SLOT(onPositionUpdated(int,int)));
	s->setText("X " + xstring + ", Y " + ystring);

}

 ...if only this all worked in qml i'd have been done days ago lol :smileywink:

 

--Edit after removing all intergers etc, i was unable to get the label text to change while on the services.cpp page so i went back to appName.cpp & the text changes like a charm

 

    AbstractPane *root = qml->createRootObject<AbstractPane>();
    Label *mLabel = root->findChild<Label*>("rootLabel");
    mLabel->setText("C++ Label");

 only, I've no clue how to pull the integer values from touchpoint.cpp's Touchpoint::getX & getY & update the text with that information from appName.cpp

Developer
Zmey
Posts: 1,512
Registered: ‎12-18-2012
My Device: PlayBook, Z10, DAC

Re: Screen Events

No problem. :smileyhappy:

 

 

The simplest approach is probably going back to the original code and replacing this line:

// such as mLabel->setText("X " + mtouch_event.x + ", Y " + mtouch_event.y);

with:

Label *rootLabel = Application::instance()->scene()->findChild<Label *>("rootLabel");
QString xString = QString::number(mtouch_event.x);
QString yString = QString::number(mtouch_event.y); rootLabel->setText("X " + xString + ", Y " + yString);

And adding

#include <bb/cascades/Application>

#include <bb/cascades/Label>

using namespace bb::cascades;

on the top of the file.

 

 


Andrey Fidrya, @zmeyc on twitter
Developer
mabouzou
Posts: 16
Registered: ‎05-02-2013
My Device: Z10 LE

Re: Screen Events

I am trying to also receive screen events using platform services. I have done screen_create_context() and screen_request_events() but I am not receiving touch events. Do you I have to create a screen (i.e. screen_create_window() ?

 

I am trying to use those events in cascades, is this even possible?