The best way to establish conversation between applications and libraries



  • I have 2 applications and 1 library. Both applications use the library and what the library does is that it informs each one of them about a progress of something that the library does. If both applications are started and one of the application tells the library to perform some action both applications should be informed about the progress of the task. The application should be able to talk to the library as well.

    Which is the best Qt technology - QSharedMemory, etc., that can be used to complete this conversational task?



  • You should look into implementing this as some sort of a client server with sockets. The server is what you call the library, and the clients the applications. The clients would connect to that server and get informed of the events over a TCP connection for example.



  • I'm a bit confused about your use of the word "library" here. I would normally take it to mean a collection of common functions or object definitions linked with the application. The answer to your question is then "just use function and method calls". I suspect you are talking about something else, though, and if you essentially mean a client-server type setup like the previous reply assumes, then, yes, you need a TCP connection or similar. Using some kind of an abstraction layer may be easier than setting up "raw" links, though. There are many ready-made protocols and software libraries (!) available these days. Which is most appropriate really depends on the application, but have a look at the "QtDBus Module" section of the Qt documentation for an option that's integrated with Qt, and is a bit of a standard for "desktop" uses.



  • I'll describe the case in greater detail:
    I have two applications that are currently running - application A1 and application A2.

    Each one of those two applications is linked with the library called L. The library L exposes a class called "Processor" which has a method called "process()" and a signal "progress(int)" that informs about the progress of the work being done by the "progress()" method.

    I want both applications (they are both started and running) to be informed about the progress, no matter which one of the applications has called "progress()".

    How to do that?



  • Just because you use a shared library doesn't mean that your two program instances use the same instance of that library. Your shared library will be loaded in each process adress space independently. You will have two copies of your library: one in application A1 and one in application A2.
    What you want to do is interprocess communication which can be implemented in a OS independent manner using sockets as I explained in my previous post.



  • bq. Just because you use a shared library doesn’t mean that your two program instances use the same instance of that library. Your shared library will be loaded in each process adress space independently. You will have two copies of your library: one in application A1 and one in application A2.

    I was just about to mention exactly this in my previous post. I know that despite being a dynamic library it is kept separately in each process' memory space.

    So, it is better in the current case to use sockets than D-Bus?



  • I am not fond of D-Bus for some reasons, one of them is that it is not cross-platform. It's a UNIX only technology. If your goal is to solely run in that environment, it is a possible choice, however I would not use it. You can do what you want fairly easily using sockets and QDataStream for object/struct serialization.



  • Have a look into QSharedMemory. This sounds perfect for your example and is cross platform too.


Log in to reply
 

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