PDA

View Full Version : QRetmoteObject communication



scgrant327
26th August 2019, 13:54
I can successfully create an Android service and use qRO to pass data from the service to my app... great!

However, I cannot seem to get this to work.

My app acts at the 'source' and the service acts as the 'client'. I need to pass some data from my app to the service once I start the service. I have tried using a SIGNAL from the 'source' to the 'client', which compiles and runs, but the SIGNAL does not appear to be received by the 'client'. I also tried using a PROP, but once I add that to my .rep, I get all sorts of errors... so the SIGNAL method seems to be my best option.

In my .rep, I have


SLOT(server_slot(bool clientState));
SIGNAL(setBgFlagSignal(bool bgFlag));

In my App:


connect(this,SIGNAL(updateBgFlag(bool)), &gpsObj, SLOT(server_slot(bool)));
bool bgFlag = false;
emit updateBgFlag(bgFlag);

My Remote Object has this:


void GpsRemoteObject::server_slot(bool clientState)
{
qDebug() << "State set to: " << clientState;
appIsForeground = !clientState;
emit setBgFlagSignal(clientState);
qDebug() << "Foreground set to: " << appIsForeground;
}

My Client (service):


repNode.connectToNode(QUrl(QStringLiteral("local:gpsremote"))); // connect with remote host node
ptr.reset(repNode.acquire<GPSRemoteObjectReplica>()); // acquire replica of source from host node
QObject::connect(ptr.data(), SIGNAL(setBgFlagSignal(bool)),this,SLOT(setBgFlag( bool)));

void Worker::setBgFlag(bool bgFlag) {
qDebug() << "1234 bgFlag set: " << bgFlag;
appIsBackground = bgFlag;
}

What I am not seeing... is appIsBackground being set in the setBgFlag SLOT...

Any ideas why?

The Client (service) passes data to the Source (and then to my app) without issues... Pretty much just the reverse of what I'm trying above. Works flawlessly.

--Sam

anda_skoa
27th August 2019, 10:18
As far as I can tell this looks OK, so I can't really help with this specific usage.

However, I would recommend switching to a property instead of a signal as you are communicating a state, not a one-of event.

So something like

gpsremoteobject.rep


class GpsRemoteObject
{
PROP(bool isBackground)
};


On the source side you can then simply call the property setter whenever the value changes


GpsRemoteObjectSimpleSource source;

//.. enable remoting, etc

source.setIsBackground(value);


On the replica side you can connect to the property's "changed" signal


connect(ptr.data(), &GpsRemoteObjectReplica::isBackgroundChanged, this, &Worker::setBgFlag);

and read directly using the property's getter function (you don't need a local variable for the state)

Cheers,
_

scgrant327
27th August 2019, 14:35
Adding in a PROP results in my class being abstract, which causes errors... Just adding in a
PROP(bool isBackground=false); and recompiling...

anda_skoa
27th August 2019, 18:53
Adding in a PROP results in my class being abstract, which causes errors

Can you post the exact error?

Cheers,
_

scgrant327
27th August 2019, 19:14
Can you post the exact error?

Cheers,
_


field typ 'GpsRemoteObject' is an abstract class - gpsio.h
unimplemented pure virtual method 'isBackground' in 'GpsRemoteObject'- rep_gpsremoteobject_source.h
unimplemented pure virtual method 'setIsBackground' in 'GpsRemoteObject' - rep_gpsremoteobject_source.h

All I did was add
PROP(bool isBackground=false); to the .rep file.

anda_skoa
28th August 2019, 09:46
Ah, yes.

The class generated by repc is pure virtual so that you can implement your own code for setting and getting a property.

But repc also generates a default implementation.

You can either

1) Derive from the generated GpsRemoteObject and implement the two virtual methods
2) Use the generated default implementation GpsRemoteObjectSimpleSource
3) Rename the class in the .rep file and make your GpsRemoteObject class the class from (1)

Cheers,
_

scgrant327
28th August 2019, 18:47
Not sure I follow. Can you explain the options a bit more?

Specifically option 2.

Added after 1 45 minutes:

Got the PROP to compile by doing #2... instancing from GpsRemoteObjectSimpleSource.

Now, I'm having issues with getting my PROP propagated from the Source to the Client.

Progress!