Skip to content

Instantly share code, notes, and snippets.

@NIA
Last active February 2, 2016 10:14
Show Gist options
  • Save NIA/37a445d0d511223198ea to your computer and use it in GitHub Desktop.
Save NIA/37a445d0d511223198ea to your computer and use it in GitHub Desktop.
qt data piping example
#include <QObject>
class Receiver : public QObject {
Q_OBJECT
// ...
signals:
void bytesReceived(QByteArray b);
// ...
}
class Parser : public QObject {
Q_OBJECT
// ..
slots:
void receiveBytes(QByteArray b);
signals:
void stringParsed(QString);
void numberParsed(int);
}
class Printer: public QObject {
Q_OBJECT
// ...
slots:
void printString(QString s);
void printNumber(int n);
}
int main() {
QCoreApplication app;
Receiver receiver(...);
Parser parser(...);
Printer printer(...);
// Receiver ---> Parser
connect(receiver, Receiver::bytesReceived, parser, Parser::receiveBytes);
// Parser ---> Printer
connect(parser, Parser::stringParsed, printer, Printer::printString);
connect(parser, Parser::numberParsed, printer, Printer::printNumber);
app.exec();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment