02-11-2013 11:17 PM - edited 02-12-2013 05:41 AM
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);
}
02-12-2013 06:17 AM
02-12-2013 12:15 PM
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 ![]()
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
02-12-2013 12:18 PM - edited 02-12-2013 12:26 PM
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.
02-12-2013 12:25 PM
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'
02-12-2013 12:28 PM - edited 02-12-2013 12:28 PM
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.
02-12-2013 01:54 PM - edited 02-12-2013 03:06 PM
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 ![]()
--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
02-12-2013 03:12 PM
No problem. ![]()
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.