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. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Cascades Development

Reply
Trusted Contributor
slashkyle
Posts: 166
Registered: ‎10-16-2012
My Carrier: Telus

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);
			}
Please use plain text.
Developer
Zmey
Posts: 896
Registered: ‎12-18-2012

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.
Please use plain text.
Trusted Contributor
slashkyle
Posts: 166
Registered: ‎10-16-2012
My Carrier: Telus

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

 

 

Please use plain text.
Developer
Zmey
Posts: 896
Registered: ‎12-18-2012

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.

 

Please use plain text.
Trusted Contributor
slashkyle
Posts: 166
Registered: ‎10-16-2012
My Carrier: Telus

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'

Please use plain text.
Developer
Zmey
Posts: 896
Registered: ‎12-18-2012

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.

 

Please use plain text.
Trusted Contributor
slashkyle
Posts: 166
Registered: ‎10-16-2012
My Carrier: Telus

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

Please use plain text.
Developer
Zmey
Posts: 896
Registered: ‎12-18-2012

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.

 

 

Please use plain text.