Home · Modules · Classes · Namespaces · Functions

QxtPipe Class Reference
[QxtCore module]

The QxtPipe class provides a pipeable QIODevice * * pipes can be connected to other pipes, to exchange data * The default implementation uses a buffer. * Reimplement to make your custom class able to be connected into a pipe chain. * * Example usage: * More...

    #include <QxtPipe>

Inherits QIODevice.

Inherited by QxtDeplex and QxtStdio.

Public Functions

Protected Functions

Additional Inherited Members


Detailed Description

* * *

The QxtPipe class provides a pipeable QIODevice * * pipes can be connected to other pipes, to exchange data * The default implementation uses a buffer. * Reimplement to make your custom class able to be connected into a pipe chain. * * Example usage: *

    * QxtPipe p1;
    * QxtPipe p2;
    * QxtPipe p3;
    * p1|p2|p3;
    * p1.write("hi. how are you?");
    * qDebug()<<p3.readAll();
    * p3.write("I'm fine, thanks.");
    * qDebug()<<p1.readAll();
    *

<h4>Subclassing</h4> When implementing your own pipe element, like a de/encoder or something, you have to reimplement receiveData() and call sendData() whenever you have something to send to the pipe network.

If you want to the user to be able to read from the device directly via the QIODevice facility you have to call enqueuData() too

If you don't want to the user to be able to write to the device directly via the QIODevice facility (that would be fatal for a decoder, for example), then reimplement the functions readData() and writeData() and return 0.

See also QxtDeplex.


Member Function Documentation

QxtPipe::QxtPipe ( QObject * parent = 0 )

Contructs a new QxtPipe with parent.

bool QxtPipe::connect ( QxtPipe * other, QIODevice::OpenMode mode = QIODevice::ReadWrite, Qt::ConnectionType connectionType = Qt::AutoConnection )

Pipes the output of this instance to the other QxtPipe using the given mode and connectionType. Returns true if succeeds. Connection pipes with this function can be considered thread safe.

Example usage:

    QxtPipe p1;
    QxtPipe p2;
    p1.connect(&p2,QIODevice::ReadOnly);

    //this data will go nowhere. p2 is connected to p1, but not p2 to p1.
    p1.write("hello");

    //while this data will end up in p1
    p2.write("world");

    qDebug()<<p1.readAll();

bool QxtPipe::disconnect ( QxtPipe * other )

Cuts the connection to the other QxtPipe and returns true if succeeds.

void QxtPipe::enqueData ( QByteArray datab )   [protected]

Call this from your subclass to make datab available to the QIODevice::read facility

void QxtPipe::receiveData ( QByteArray datab, const QxtPipe * sender )   [virtual protected]

This function is called from any connected pipe to input datab from sender into this instance. Reimplement this function to handle data from the pipe network.

The default implementation calls enqueData() and sendData().

void QxtPipe::sendData ( QByteArray data ) const   [protected]

Call this from your subclass to write data to the pipe network. All write connected pipes will be invoked with receiveData In this case this is called from receiveData, the sender will be excluded from the receiver list.

QxtPipe & QxtPipe::operator| ( QxtPipe & target )

Convenience function for QxtPipe::connect(). Pipes the output of this instance to the target QxtPipe in readwrite mode with auto connection.


Copyright © 2007-2011 Qxt Foundation
Qxt 0.6.2