Results 1 to 4 of 4

Thread: Named pipes in Qt

  1. #1
    Join Date
    Jul 2008
    Posts
    4

    Lightbulb Named pipes in Qt

    Linux and windows can create what are called named pipes. They are basically a cross between a file and a pipe, or a socket.

    For example, in linux this can be done using the mkfifo line command. This creates a permanent identifier in the file system which can be open by two or more programs and share data through it, as if it were a file, using the common file writing and reading calls from the system.

    Windows offers as well some system calls to create named pipes in the file system, and use them while they are kept open by the application.

    We're creating an image and video processing tool which communicates with the MPlayer application through this kind of pipes. Using sockets might be a bit of slow down, and the MPlayer is not prepared to work using common pipes.

    To solve this we create a named pipe, and execute a copy of the MPlayer. We launch it properly configured to decode a video file or read from a digital camera and dump the data in an easy readable format to an end of the named pipe.
    The other end is connected to an image processing thread created by our application.

    We've created a class of the Qt style named QNamedPipe:

    Qt Code:
    1. class QNamedPipe: public QObject
    2. {
    3. Q_OBJECT;
    4. public:
    5. QNamedPipe();
    6. ~QNamedPipe();
    7.  
    8. QString getInputFilePath() const;
    9. QString getOutputFilePath() const;
    10. };
    To copy to clipboard, switch view to plain text mode 

    Its basic usage is as follows: to create a named pipe, create an object from that class. To get an end's name, use functions 'getInputFilePath' and 'getOutputFilePath'. To destroy the named pipe just delete the object.

    Could it be interesting to include such a class (or alike) to create named pipes in Qt? How could this be proposed to the trolls?

    We've just developed the class to work on linux, but it may be helpful if it were also for windows.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Named pipes in Qt

    Have you noticed QLocalSocket?
    J-P Nurmi

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Named pipes in Qt

    There is a QLocalSocket class since Qt4.4 which uses named pipes on Windows and local sockets on Unix. I guess it might be doing more or less what your class does.

  4. #4
    Join Date
    Jan 2006
    Posts
    132
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Named pipes in Qt

    Unfortunately QLocalSocket prevents from connecting to other servers, and only allows to connect to local pipe servers (well, surely to satisfy the "Local" in the class name.

    With a small hack that could be fixed however, I think changing the server name adjustment in qlocalsocket_win.cpp could do the trick:

    Original:
    Qt Code:
    1. QString pipePath = QLatin1String("\\\\.\\pipe\\");
    2. if (name.startsWith(pipePath))
    3. d->fullServerName = name;
    4. else
    5. d->fullServerName = pipePath + name;
    To copy to clipboard, switch view to plain text mode 

    Hacked:
    Qt Code:
    1. QString pipePath = QLatin1String("\\\\.\\pipe\\");
    2. if (name.startsWith(QLatin1String("\\\\")))
    3. d->fullServerName = name;
    4. else
    5. d->fullServerName = pipePath + name;
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Edyuk : fully-featured, highly flexible and free cross-platform IDE
    By fullmetalcoder in forum Qt-based Software
    Replies: 169
    Last Post: 20th July 2009, 11:42
  2. class QHBoxLayout
    By csvivek in forum Installation and Deployment
    Replies: 2
    Last Post: 10th April 2008, 07:57
  3. QProcess pipes problem
    By benacler in forum Qt Programming
    Replies: 6
    Last Post: 7th December 2007, 18:30
  4. QProcess and Pipes
    By KaptainKarl in forum Qt Programming
    Replies: 1
    Last Post: 9th April 2007, 23:11

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.