Last active
February 2, 2016 10:14
-
-
Save NIA/37a445d0d511223198ea to your computer and use it in GitHub Desktop.
qt data piping example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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