Qt - 多个 IPC 应用程序的多个共享内存空间?
我对 Qt 有点陌生,我试图了解共享内存应用程序,以及当您有多个使用共享内存但不应该交互的软件时会发生什么。
我正在看这个基本演示/示例: http:// doc.qt.io/qt-5/qtcore-ipc-sharedmemory-example.html
假设我开发软件应用程序 A 和软件应用程序 B。这两个应用程序都使用 Qt 的共享内存,并且可以相互通信使用共享内存。
然后假设用户也正在运行软件应用程序 X,该应用程序也恰好将 Qt 的共享内存用于其他目的。软件应用程序X与应用程序A和应用程序B完全无关。
查看Qt共享内存的文档,我不明白您的应用程序如何以与尝试使用共享内存的其他应用程序不同的方式使用共享内存。是什么阻止 App X 通过共享内存向 App A 和 App B 发送垃圾数据?
另外,关于上述示例的一个大问题是,对于 Qt 的共享内存演示,它们使用一个您运行多次的应用程序,并且共享内存的内容发生在它们之间。您是否能够开发两个完全不同的软件,通过共享内存协同工作,还是仅限于打开多个实例的单个应用程序?
I'm a bit new to Qt and I'm trying to understand Shared Memory applications and what happens when you have multiple pieces of software that use Shared Memory but are not supposed to interact.
I'm looking at this basic demo/example: http://doc.qt.io/qt-5/qtcore-ipc-sharedmemory-example.html
Lets say I develop software app A and software app B. Both of these apps use Qt's Shared Memory and are made to communicate to eachother using Shared Memory.
Then lets say the user also is running software app X that also happens to use Qt's Shared Memory for some other purpose. Software app X is completely UNRELATED to app A and app B.
Looking at the documentation for Qt's Shared Memory, I don't understand how your application use's Shared Memory in a way that differentiates itself from other applications attempting to use Shared Memory. What is keeping App X from sending garbage data to App A and App B via Shared Memory?
Also, one big question about the above example is that for Qt's Shared Memory demo, they use a single application that you run more than once and the Shared Memory stuff happens between them. Are you able to develop two completely different pieces of software that work together via Shared Memory or is it limited to a single application that is has multiple instances open?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用您的应用程序共享的密钥。因此可以通过构造函数设置:
QSharedMemory::QSharedMemory ( const QString & key, QObject *parent = 0 )
或者函数 setKey():
void QSharedMemory::setKey ( const QString & key )
但是,如果另一个应用程序使用了相同的密钥,或者猜测您的密钥,您可能会遇到麻烦。因此,防止这种情况的一种方法是使用某种形式的混淆来生成密钥。
共享内存的使用是在同一主机上的不同进程之间共享数据。因此,可能是同一应用程序或其他应用程序的多个实例知道或共享密钥。
You make use of a key that your applications share. Thus can be set via the constructor:
QSharedMemory::QSharedMemory ( const QString & key, QObject * parent = 0 )
Or the function setKey():
void QSharedMemory::setKey ( const QString & key )
But, if another application used the same key, or guess your key you can have trouble. Thus, one way to protect against this is some form of obfuscation to generate your key.
The use of shared memory is to share data between separate processes on the same host. Thus, it might be multiple instances of the same application or other applications that know or share the key.