Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. RemoteObjects - passing pointer to my class instance
Forum Updated to NodeBB v4.3 + New Features

RemoteObjects - passing pointer to my class instance

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
10 Posts 3 Posters 2.0k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vlada
    wrote on 13 Oct 2017, 22:58 last edited by
    #1

    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?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 14 Oct 2017, 20:13 last edited by
      #2

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • V Offline
        V Offline
        vlada
        wrote on 15 Oct 2017, 19:30 last edited by
        #3

        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?

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 15 Oct 2017, 20:18 last edited by
          #4

          What are you thinking is not possible ?

          The application code you wrote is incomplete.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • V Offline
            V Offline
            vlada
            wrote on 16 Oct 2017, 08:18 last edited by
            #5

            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?

            J 1 Reply Last reply 16 Oct 2017, 09:11
            0
            • V vlada
              16 Oct 2017, 08:18

              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?

              J Offline
              J Offline
              jsulm
              Lifetime Qt Champion
              wrote on 16 Oct 2017, 09:11 last edited by
              #6

              @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).

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • V Offline
                V Offline
                vlada
                wrote on 16 Oct 2017, 09:54 last edited by
                #7

                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.

                J 1 Reply Last reply 16 Oct 2017, 09:59
                0
                • V vlada
                  16 Oct 2017, 09:54

                  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.

                  J Offline
                  J Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on 16 Oct 2017, 09:59 last edited by
                  #8

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

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  V 1 Reply Last reply 16 Oct 2017, 10:34
                  0
                  • J jsulm
                    16 Oct 2017, 09:59

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

                    V Offline
                    V Offline
                    vlada
                    wrote on 16 Oct 2017, 10:34 last edited by
                    #9

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

                    J 1 Reply Last reply 16 Oct 2017, 10:37
                    0
                    • V vlada
                      16 Oct 2017, 10:34

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

                      J Offline
                      J Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on 16 Oct 2017, 10:37 last edited by
                      #10

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

                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0

                      1/10

                      13 Oct 2017, 22:58

                      • Login

                      • Login or register to search.
                      1 out of 10
                      • First post
                        1/10
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved