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. Is is possible to create a semaphore accessable to both Windows and Qt applications?
Forum Update on Monday, May 27th 2025

Is is possible to create a semaphore accessable to both Windows and Qt applications?

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 2.6k Views
  • 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.
  • C Offline
    C Offline
    cyao
    wrote on last edited by
    #1

    I tried to create a named semaphore in a Windows application using following code:

    m_hSemaphore = ::CreateSemaphore(NULL, 0, 100, "semaphore_test");
    

    and in my Qt application I open a semaphore of the same name:

    pSemaphore = new QSystemSemaphore(tr("semaphore_test"), 0, QSystemSemaphore::Open);
    

    But when the semaphore is released in Windows application, in Qt application,

    m_pSemaphore->acquire();
    

    is still blocked, which means two applications are not accessing the samesemaphore.

    Is there a way to make both applications access the same semaphore? The similar problem also exists in accessing shared memory in both Windows and Qt applications.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      MuldeR
      wrote on last edited by
      #2

      AFAIK Qt will decorate the Semaphore name, when using QSystemSemaphore().

      You can use a tool such as ProcessExplorer to lookup the actual (native) name of the Semaphore...

      http://technet.microsoft.com/de-de/sysinternals/bb896653.aspx

      !http://imageshack.us/a/img690/9056/clipboard01yi.png(Screenshot from ProcessExplorer)!

      Looks like the string "qipc_systemsem_" followed by a hash of the specified string is used ;-)

      My OpenSource software at: http://muldersoft.com/

      Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

      Go visit the coop: http://youtu.be/Jay...

      1 Reply Last reply
      0
      • M Offline
        M Offline
        MuldeR
        wrote on last edited by
        #3

        bq. Thank you very much for your help! Now I can make Windows application and Qt application use a same semaphore.
        ProcessExplorer does not show shared memory used by a process, so making Windows application and Qt application use same shared memory is still a problem. Any ideas?

        The "shared" memory is nothing but a "memory mapped file", one that is backed by the system page file rather than by a file system file. Doesn't it show up under the file handles in ProcessExplorer?

        My OpenSource software at: http://muldersoft.com/

        Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

        Go visit the coop: http://youtu.be/Jay...

        1 Reply Last reply
        0
        • C Offline
          C Offline
          cyao
          wrote on last edited by
          #4

          No, it does not show up.

          1 Reply Last reply
          0
          • M Offline
            M Offline
            MuldeR
            wrote on last edited by
            #5

            I'm now at home and just check it. It does show up! But as a "section", not as a "file" ;-)

            Example:
            @\Sessions\1\BaseNamedObjects\qipc_sharedmemory_AAbbCFBFEEc953e91dc88f95245766d85214a816f620994f01@

            My OpenSource software at: http://muldersoft.com/

            Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

            Go visit the coop: http://youtu.be/Jay...

            1 Reply Last reply
            0
            • C Offline
              C Offline
              cyao
              wrote on last edited by
              #6

              I see, thanks! By the way, I just noticed that QSharedMemory::setNativeKey will set the native, platform specific key for this shared memory object, that will also help in Qt code to connect to shared memory created from Windows code.

              1 Reply Last reply
              0

              • Login

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