Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QSharedMemory: IPC problem between apps which built on Qt 4.6 and Qt 5.6
Forum Updated to NodeBB v4.3 + New Features

QSharedMemory: IPC problem between apps which built on Qt 4.6 and Qt 5.6

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 1.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    VMironiuk
    wrote on 12 Apr 2016, 14:12 last edited by VMironiuk 4 Dec 2016, 14:30
    #1

    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.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 13 Apr 2016, 07:17 last edited by
      #2

      Hi and welcome to devnet,

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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      V 1 Reply Last reply 13 Apr 2016, 08:47
      1
      • S SGaist
        13 Apr 2016, 07:17

        Hi and welcome to devnet,

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

        V Offline
        V Offline
        VMironiuk
        wrote on 13 Apr 2016, 08:47 last edited by
        #3

        @SGaist
        Ok, thank you for response.

        V 1 Reply Last reply 13 Apr 2016, 17:18
        0
        • V VMironiuk
          13 Apr 2016, 08:47

          @SGaist
          Ok, thank you for response.

          V Offline
          V Offline
          VMironiuk
          wrote on 13 Apr 2016, 17:18 last edited by
          #4

          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.

          1 Reply Last reply
          0

          2/4

          13 Apr 2016, 07:17

          • Login

          • Login or register to search.
          2 out of 4
          • First post
            2/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved