Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How send data between two instances of same application
Forum Updated to NodeBB v4.3 + New Features

How send data between two instances of same application

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 4 Posters 827 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.
  • D Offline
    D Offline
    dporobic
    wrote on 11 May 2020, 08:58 last edited by
    #1

    As the title says it, how can I send data between two instances of the same application or in general, between two Qt application. The data will be probably very small, just a parameter object with few strings. The instances don't know about each other so I need first to find any existing instances. Any suggestion for a lightweight solution?

    https://github.com/ksnip/ksnip

    J 1 Reply Last reply 11 May 2020, 09:02
    0
    • D dporobic
      11 May 2020, 08:58

      As the title says it, how can I send data between two instances of the same application or in general, between two Qt application. The data will be probably very small, just a parameter object with few strings. The instances don't know about each other so I need first to find any existing instances. Any suggestion for a lightweight solution?

      J Offline
      J Offline
      J.Hilk
      Moderators
      wrote on 11 May 2020, 09:02 last edited by
      #2

      hi @dporobic

      the first things that come to my mind are

      • Sockets (TCP/UDP)
      • QSettings(with the same source file)
      • QRemoteObject
      • QSharedMemory

      The most light option is probably QSettings, but you'll have to regularly check, if the File changed or not and it relies on the FileSystem.
      So I would suggest QSharedMemory, (if the shared data is reasonably small)


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      8
      • B Offline
        B Offline
        beecksche
        wrote on 11 May 2020, 09:07 last edited by
        #3

        There are several methods in Qt: https://doc.qt.io/qt-5/ipc.html

        1 Reply Last reply
        4
        • D Offline
          D Offline
          dporobic
          wrote on 11 May 2020, 09:11 last edited by
          #4

          Hey @J-Hilk thanks for the quick reply. The amount of data is small, its basically 0 to ~5 strings or booleans. Can I get notified when new data is available in QSharedMemory? Can't see any signals or slots on the documentation page.

          https://github.com/ksnip/ksnip

          J 1 Reply Last reply 11 May 2020, 09:15
          0
          • D dporobic
            11 May 2020, 09:11

            Hey @J-Hilk thanks for the quick reply. The amount of data is small, its basically 0 to ~5 strings or booleans. Can I get notified when new data is available in QSharedMemory? Can't see any signals or slots on the documentation page.

            J Offline
            J Offline
            J.Hilk
            Moderators
            wrote on 11 May 2020, 09:15 last edited by
            #5

            @dporobic said in How send data between two instances of same application:

            Can I get notified when new data is available in QSharedMemory? Can't see any signals or slots on the documentation page.

            I don't think it's build in.
            But here's an interesting solution to the situation
            https://forum.qt.io/topic/26298/solved-qsharedmemory-checking


            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            1 Reply Last reply
            3
            • J Offline
              J Offline
              JoeCFD
              wrote on 11 May 2020, 19:37 last edited by
              #6

              QSharedMemory will work. QLocalSocket will work either.

              1 Reply Last reply
              3
              • D Offline
                D Offline
                dporobic
                wrote on 15 May 2020, 07:12 last edited by
                #7

                I've ended up using QLocalSocket and QLocalServer which seem to be working and lightweight. One drawback is that only ByteArrays are sent between the Caller and Sender, I'm working around that by converting my object to ByteArrays messages on one side and back to objects on the other.

                In case someone is looking for a solution:
                https://github.com/ksnip/ksnip/blob/master/src/backend/ipc/IpcServer.h
                https://github.com/ksnip/ksnip/blob/master/src/backend/ipc/IpcServer.cpp
                https://github.com/ksnip/ksnip/blob/master/src/backend/ipc/IpcClient.h
                https://github.com/ksnip/ksnip/blob/master/src/backend/ipc/IpcClient.cpp

                https://github.com/ksnip/ksnip

                1 Reply Last reply
                2

                1/7

                11 May 2020, 08:58

                • Login

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