RemoteObjects - passing pointer to my class instance



  • Hi,

    I created an Android service using this guide.

    After some problems I managed to add it to my project. Now I have following problem:

    I have a class and I need to pass a pointer to an instance of this class to the service. The first question is: Is it possible at all that the main app and the service share the same object? I hope this is what RemoteObjects enables.

    There is the .rep file which defines the interface between the app and the service. Now it is the same as in the example:

    class PingPong {
        SLOT(void ping(const QString &msg));
        SIGNAL(pong(const QString &msg));
    }
    

    I tried to add these lines:

    #include myclass.h
    SLOT(void setPointer(const MyClass &mc));
    

    But this doesn't work. Does such code make sense at all? What should be the correct solution?


  • Lifetime Qt Champion

    Hi,

    Not it doesn't.

    You have the actual implementation just under "QtRemoteObjects source(server) side implementation".

    Otherwise, take a look at Qt RemoteObjects getting started guide.



  • Thank you. I was afraid that this will not be possible. What do you think would be the best solution?

    I think about creating an instance of my class in both service and main app. And then share via slot/signal if an attribute of the class has changed. Is it a good idea? Is there a better way to synchronize data between main app and it's service?


  • Lifetime Qt Champion

    What are you thinking is not possible ?

    The application code you wrote is incomplete.



  • I was thinking about sharing the same object (instance of my own class) between my main app and it's service.

    I'm not sure if it is possible since those are 2 different processes and they should access the same memory in this case. But maybe QtRemoteObjects have a solution for this. I was not able to find this in the documentation.

    Do you think it is possible to share the same object between main process and a service?


  • Moderators

    @vlada said in RemoteObjects - passing pointer to my class instance:

    Do you think it is possible to share the same object between main process and a service?

    Should be possible using shared memory. But why do you want to do this? It is complex and you would need to care about synchronisation (read/write from/to same piece of memory from two processes at the same time).



  • I need to share the same configuration between the main app (mainly the GUI) and the service part.

    My idea is that I will create 2 instances of the object holding the configuration and synchronize the data by slots and signals between them. That would eliminate the need of sharing the same memory and would not not be too complicated. What do you think?

    Thanks a lot for your help.


  • Moderators

    @vlada said in RemoteObjects - passing pointer to my class instance:

    That would eliminate the need of sharing the same memory and would not not be too complicated.

    This is not possible: signals/slots do not work across processes.



  • @jsulm They do. This is exactly what the extension QtRemoteObjects is made for.


  • Moderators

    @vlada OK, understood. This way it should be possible, yes.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.