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
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