问题
I'm looking for suggestions about choosing a portable way to achieve local IPC in a robust way, since i'm new to C++ and would like to avoid common pitfalls of fiddling with shared memory and locks; therefore I was thinking about message-passing style ipc.
I was planning to use qt for other reasons anyway, thus i took a peek to Qt ipc options.
if i understand correctly qt doesn't offer a completely portable message-passing ipc feature. it can use d-bus, but using it on windows would be a problem. other ways are limited to embedded linux platforms (and i would like to port this thing to AIX).
I could not find a "signal and slots" or message-passing style implementation that uses QSharedMemory and QSystemSemaphores
Thus: Am I limited to implement a feature on QSM/QSS? what other options could i study? posix pipes? protocol buffers? boost queues and messages ?
I'm considering to release the code under LGPL/GPL style license, does this rule out protocol buffers or boost libs?
please, again, the interface must be simple and newbie-proof (otherwise i definitely will screw up things big time for sure :) ), and so should the serialization/deserialization of types, error handling and resource disposal.
回答1:
Take a look at Boost.Interprocess which provides a lot of IPC functionality. I have used the interprocess message_queue that provides a pretty clean and easy way to do what I think you want to do.
回答2:
You can use QLocalSocket and QlocalServer for IPC too. Those two classes are really easy to use and they can be implemented ~almost the same way as you would using Qt TCP socket client/server.
You can take a look at some of these youtube videos:
QTCPServer - a basic TCP server application
QTcpServer using multiple threads
(Almost the sames principles would apply for "Local" server/client instead of "TCP")
回答3:
As Qt 5.9, there is module which is currently under technology preview name QtRemoteObjects which provides Qt native IPC for QObjects, its easy to use and could be used to share signal/slots and also models between two processes.
Its works well for Linux, Windows and android
来源:https://stackoverflow.com/questions/1717540/qt-portable-ipc-only-qsharedmemory