Results 1 to 7 of 7

Thread: QRetmoteObject communication

  1. #1
    Join Date
    May 2011
    Posts
    81
    Thanks
    6
    Thanked 5 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default 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

    Qt Code:
    1. SLOT(server_slot(bool clientState));
    2. SIGNAL(setBgFlagSignal(bool bgFlag));
    To copy to clipboard, switch view to plain text mode 

    In my App:

    Qt Code:
    1. connect(this,SIGNAL(updateBgFlag(bool)), &gpsObj, SLOT(server_slot(bool)));
    2. bool bgFlag = false;
    3. emit updateBgFlag(bgFlag);
    To copy to clipboard, switch view to plain text mode 

    My Remote Object has this:

    Qt Code:
    1. void GpsRemoteObject::server_slot(bool clientState)
    2. {
    3. qDebug() << "State set to: " << clientState;
    4. appIsForeground = !clientState;
    5. emit setBgFlagSignal(clientState);
    6. qDebug() << "Foreground set to: " << appIsForeground;
    7. }
    To copy to clipboard, switch view to plain text mode 

    My Client (service):

    Qt Code:
    1. repNode.connectToNode(QUrl(QStringLiteral("local:gpsremote"))); // connect with remote host node
    2. ptr.reset(repNode.acquire<GPSRemoteObjectReplica>()); // acquire replica of source from host node
    3. QObject::connect(ptr.data(), SIGNAL(setBgFlagSignal(bool)),this,SLOT(setBgFlag(bool)));
    4.  
    5. void Worker::setBgFlag(bool bgFlag) {
    6. qDebug() << "1234 bgFlag set: " << bgFlag;
    7. appIsBackground = bgFlag;
    8. }
    To copy to clipboard, switch view to plain text mode 

    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
    Last edited by scgrant327; 26th August 2019 at 17:14.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default 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
    Qt Code:
    1. class GpsRemoteObject
    2. {
    3. PROP(bool isBackground)
    4. };
    To copy to clipboard, switch view to plain text mode 

    On the source side you can then simply call the property setter whenever the value changes
    Qt Code:
    1. GpsRemoteObjectSimpleSource source;
    2.  
    3. //.. enable remoting, etc
    4.  
    5. source.setIsBackground(value);
    To copy to clipboard, switch view to plain text mode 

    On the replica side you can connect to the property's "changed" signal
    Qt Code:
    1. connect(ptr.data(), &GpsRemoteObjectReplica::isBackgroundChanged, this, &Worker::setBgFlag);
    To copy to clipboard, switch view to plain text mode 
    and read directly using the property's getter function (you don't need a local variable for the state)

    Cheers,
    _

  3. #3
    Join Date
    May 2011
    Posts
    81
    Thanks
    6
    Thanked 5 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: QRetmoteObject communication

    Adding in a PROP results in my class being abstract, which causes errors... Just adding in a
    PROP(bool isBackground=false);
    and recompiling...

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QRetmoteObject communication

    Quote Originally Posted by scgrant327 View Post
    Adding in a PROP results in my class being abstract, which causes errors
    Can you post the exact error?

    Cheers,
    _

  5. #5
    Join Date
    May 2011
    Posts
    81
    Thanks
    6
    Thanked 5 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: QRetmoteObject communication

    Quote Originally Posted by anda_skoa View Post
    Can you post the exact error?

    Cheers,
    _
    Qt Code:
    1. field typ 'GpsRemoteObject' is an abstract class - gpsio.h
    2. unimplemented pure virtual method 'isBackground' in 'GpsRemoteObject'- rep_gpsremoteobject_source.h
    3. unimplemented pure virtual method 'setIsBackground' in 'GpsRemoteObject' - rep_gpsremoteobject_source.h
    To copy to clipboard, switch view to plain text mode 

    All I did was add
    Qt Code:
    1. PROP(bool isBackground=false);
    To copy to clipboard, switch view to plain text mode 
    to the .rep file.

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default 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,
    _

  7. #7
    Join Date
    May 2011
    Posts
    81
    Thanks
    6
    Thanked 5 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default 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!
    Last edited by scgrant327; 28th August 2019 at 18:47.

Similar Threads

  1. Communication with USB
    By prasenjit in forum Qt Programming
    Replies: 2
    Last Post: 13th June 2010, 01:19
  2. Qt and .Net communication
    By soniaerm in forum Qt Programming
    Replies: 0
    Last Post: 22nd April 2010, 07:37
  3. Example of SSL communication
    By Morea in forum Qt Programming
    Replies: 4
    Last Post: 26th January 2009, 00:41
  4. USB communication
    By M. Bashir in forum Qt Programming
    Replies: 1
    Last Post: 29th January 2008, 03:56
  5. Communication Help Pls
    By munna in forum Newbie
    Replies: 1
    Last Post: 25th May 2006, 14:22

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.