QRetmoteObject communication
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
Code:
SLOT(server_slot(bool clientState));
SIGNAL(setBgFlagSignal(bool bgFlag));
In my App:
Code:
connect(this,SIGNAL(updateBgFlag(bool)), &gpsObj, SLOT(server_slot(bool)));
bool bgFlag = false;
emit updateBgFlag(bgFlag);
My Remote Object has this:
Code:
void GpsRemoteObject::server_slot(bool clientState)
{
qDebug() << "State set to: " << clientState;
appIsForeground = !clientState;
emit setBgFlagSignal(clientState);
qDebug() << "Foreground set to: " << appIsForeground;
}
My Client (service):
Code:
repNode.
connectToNode(QUrl(QStringLiteral
("local:gpsremote")));
// connect with remote host nodeptr.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
Re: QRetmoteObject communication
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
Code:
class GpsRemoteObject
{
PROP(bool isBackground)
};
On the source side you can then simply call the property setter whenever the value changes
Code:
GpsRemoteObjectSimpleSource source;
//.. enable remoting, etc
source.setIsBackground(value);
On the replica side you can connect to the property's "changed" signal
Code:
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,
_
Re: QRetmoteObject communication
Adding in a PROP results in my class being abstract, which causes errors... Just adding in a
Quote:
PROP(bool isBackground=false);
and recompiling...
Re: QRetmoteObject communication
Quote:
Originally Posted by
scgrant327
Adding in a PROP results in my class being abstract, which causes errors
Can you post the exact error?
Cheers,
_
Re: QRetmoteObject communication
Quote:
Originally Posted by
anda_skoa
Can you post the exact error?
Cheers,
_
Code:
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
Code:
PROP(bool isBackground=false);
to the .rep file.
Re: QRetmoteObject communication
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,
_
Re: QRetmoteObject communication
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!