QSharedMemory: IPC problem between apps which built on Qt 4.6 and Qt 5.6
-
Hi!
I have small application (was wrote on Qt 5.6.0) which creates shared memory segment and starts external program which I got from examples of Qt 4.6.0 (/mainwindows/application). Here the main class of my app:#define QT_56 #include <QtWidgets> class SMTest : public QWidget { Q_OBJECT public: explicit SMTest(QWidget *parent = Q_NULLPTR) : QWidget(parent), _sharedMemory("hello_world", this) { _sharedMemory.create(sizeof(double)); QPushButton *goButton = new QPushButton("Go!"); connect(goButton, SIGNAL(clicked()), this, SLOT(go())); setLayout(new QHBoxLayout); layout()->addWidget(goButton); resize(200, 100); } private slots: void go() { QString pathChunk; #ifdef QT_56 pathChunk = "/SharedMemoryTesting/application_qt56/application"; #else pathChunk = "/SharedMemoryTesting/application_qt46/application"; #endif QProcess *process = new QProcess(this); process->start(QDir::homePath() + pathChunk); } private: QSharedMemory _sharedMemory; };
In Qt's example I just added a function for attaching to the shared memory segment and writing some info to a log file (this function is called in the constructor of main window). You can see the code below:
void MainWindow::connectToSegment() { QFile file(QDir::homePath() + "/sharedMem_qt46.txt"); file.open(QIODevice::WriteOnly | QIODevice::Text); QTextStream out(&file); QSharedMemory *sm = new QSharedMemory("hello_world", this); if (!sm->attach()) { out << sm->errorString() << "\n"; } else { out << "Everything good!\n"; } }
When I run an example from my application it doesn't attach to the shared memory segment and the log file ( "sharedMem_qt46.txt") has the following error: QSharedMemory::attach (shmget): doesn't exist.
But if I take the same example from Qt 5.6.0 and run with my app, it works fine.
Maybe is this Qt's bug?P.S.
I use Debian 8 and don't know whether this problem will occur on other platforms.Up.
On Windows 8.1 x64 works fine. -
Hi and welcome to devnet,
Qt 4.6 being pretty old, I'd recommend moving to at least 4.8.7 and check again.