Important: Please read the Qt Code of Conduct -

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
        explicit SMTest(QWidget *parent = Q_NULLPTR)
            : QWidget(parent), _sharedMemory("hello_world", this)
            QPushButton *goButton = new QPushButton("Go!");
            connect(goButton, SIGNAL(clicked()), this, SLOT(go()));
            setLayout(new QHBoxLayout);
            resize(200, 100);
    private slots:
        void go()
            QString pathChunk;
    #ifdef QT_56
            pathChunk = "/SharedMemoryTesting/application_qt56/application";
            pathChunk = "/SharedMemoryTesting/application_qt46/application";
            QProcess *process = new QProcess(this);
            process->start(QDir::homePath() + pathChunk);
        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"); | 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?

    I use Debian 8 and don't know whether this problem will occur on other platforms.

    On Windows 8.1 x64 works fine.

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Qt 4.6 being pretty old, I'd recommend moving to at least 4.8.7 and check again.

  • @SGaist
    Ok, thank you for response.

  • Qt 4.8.6 has the same problem.
    On Qt 5.4.2 works fine.
    I think, the best solution is the moving to 5.6.0 version.

Log in to reply