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. QSocketNotifier with Win32 NamedPipes
Forum Updated to NodeBB v4.3 + New Features

QSocketNotifier with Win32 NamedPipes

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 4 Posters 765 Views 2 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.
  • C Offline
    C Offline
    Clemens Wasser
    wrote on last edited by
    #1

    Hey,
    I want to use Win32 NamedPipes with QSocketNotifier, but I can't get it working.
    Here is the reproducer: https://github.com/clemenswasser/named_pipes_socket_notifier
    Writing into the pipe and reading from the other end works correctly, but listening with the QSocketNotifier somehow doesn't work.
    I would expect it to print:

    Sent message
    Got message
    

    But that doesn't happen. Does anyone know what I'm doing wrong?

    SGaistS 1 Reply Last reply
    0
    • C Clemens Wasser

      Hey,
      I want to use Win32 NamedPipes with QSocketNotifier, but I can't get it working.
      Here is the reproducer: https://github.com/clemenswasser/named_pipes_socket_notifier
      Writing into the pipe and reading from the other end works correctly, but listening with the QSocketNotifier somehow doesn't work.
      I would expect it to print:

      Sent message
      Got message
      

      But that doesn't happen. Does anyone know what I'm doing wrong?

      SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Depending on what you want to achieve, would QLocalSocket be easier to use ?

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

      C 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi and welcome to devnet,

        Depending on what you want to achieve, would QLocalSocket be easier to use ?

        C Offline
        C Offline
        Clemens Wasser
        wrote on last edited by
        #3

        @SGaist
        No, for the project I'm working on we already have a NamedPipe HANDLE which we create ourselves. Using QLocalSocket is not easily possible. I just want to know what I'm doing wrong or what QLocalSocket (which uses NamesPipes as far as I know) does differently...

        Kent-DorfmanK 1 Reply Last reply
        0
        • C Clemens Wasser

          @SGaist
          No, for the project I'm working on we already have a NamedPipe HANDLE which we create ourselves. Using QLocalSocket is not easily possible. I just want to know what I'm doing wrong or what QLocalSocket (which uses NamesPipes as far as I know) does differently...

          Kent-DorfmanK Offline
          Kent-DorfmanK Offline
          Kent-Dorfman
          wrote on last edited by
          #4

          @Clemens-Wasser I could be off-base but when using named pipes you should be using the file IO calls, not socket IO, right?

          named pipes are essentially files, not sockets.

          C 1 Reply Last reply
          0
          • Kent-DorfmanK Kent-Dorfman

            @Clemens-Wasser I could be off-base but when using named pipes you should be using the file IO calls, not socket IO, right?

            named pipes are essentially files, not sockets.

            C Offline
            C Offline
            Clemens Wasser
            wrote on last edited by
            #5

            @Kent-Dorfman Yes NamedPipes use file IO calls: https://learn.microsoft.com/en-us/windows/win32/ipc/named-pipe-operations
            As you can see from my example, I'm using file IO calls and that works as expected.
            QLocalSockets use NamedPipes on Windows (https://doc.qt.io/qt-6/qlocalsocket.html#details) and that should work for QSocketNotifier.
            The docs for QSocketNotifier explicitly mention that:

            Although the class is called QSocketNotifier, it is normally used for other types of devices than sockets

            (https://doc.qt.io/qt-6/qlocalsocket.html#details)
            I've also seen many examples where they are using stdin with QSocketNotifier, so using file IO shoud be fine.

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

              @SGaist you suggested using QLocalSockets for this.
              I've updated my example with an implementation using QLocalSockets, but that one also doesn't work? :(
              QLocalSocket also uses NamedPipes on Windows, so maybe QSocketNotifier just doesn't support NamedPipes?

              K 1 Reply Last reply
              0
              • C Clemens Wasser

                @SGaist you suggested using QLocalSockets for this.
                I've updated my example with an implementation using QLocalSockets, but that one also doesn't work? :(
                QLocalSocket also uses NamedPipes on Windows, so maybe QSocketNotifier just doesn't support NamedPipes?

                K Offline
                K Offline
                kuzulis
                Qt Champions 2020
                wrote on last edited by
                #7

                @Clemens-Wasser

                Use QWinEventNotifier or something like that to watch for the Windows events in a HANDLE.

                C 1 Reply Last reply
                0
                • K kuzulis

                  @Clemens-Wasser

                  Use QWinEventNotifier or something like that to watch for the Windows events in a HANDLE.

                  C Offline
                  C Offline
                  Clemens Wasser
                  wrote on last edited by
                  #8

                  @kuzulis That also doesn't work for me (I modified my example, but the callback still doesn't get called). QWinEventHandler (as the name would suggest) only seems to work for event objects and not for NamedPipes.

                  K 1 Reply Last reply
                  0
                  • C Clemens Wasser

                    @kuzulis That also doesn't work for me (I modified my example, but the callback still doesn't get called). QWinEventHandler (as the name would suggest) only seems to work for event objects and not for NamedPipes.

                    K Offline
                    K Offline
                    kuzulis
                    Qt Champions 2020
                    wrote on last edited by kuzulis
                    #9

                    @Clemens-Wasser

                    sorry?

                    You need to use the QWinEventNotifier in the ReadFile, WriteFile, and ConnectToPipe functions, just fill the OVERLAPPED.hEvent field with the CreateEvent.

                    OR, you can copy/paste the private QWinOverlappedIONotifier which was deprecated a while time ago to watch an events directly on a HANDLE. See, e.g.sources of the QSerialPort, as I remember, as an example.

                    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