-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
47 lines (37 loc) · 1.07 KB
/
main.cpp
File metadata and controls
47 lines (37 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <QCoreApplication>
#include <QDebug>
#include <QTimer>
#include "pipelistener.h"
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
enum PIPES { READ, WRITE };
int count{0};
int pipe_fds[2];
int res = PipeNew(pipe_fds);
Q_ASSERT_X(res == 0, "main", "Error creating the pipe");
PipeListener listener(pipe_fds[READ]);
QObject::connect(&listener, &PipeListener::dataRead, [&](const QString &str) {
qDebug() << "Echo :" << str;
if (str.compare("q", Qt::CaseInsensitive) == 0) {
qDebug() << "adios!";
app.quit();
}
});
QTimer timer;
QObject::connect(&timer, &QTimer::timeout, [&] {
if (count++ < 5) {
PipeWrite(pipe_fds[WRITE], "hola!", 5);
} else {
PipeWrite(pipe_fds[WRITE], "q", 1);
timer.stop();
}
listener.emitReadyRead();
});
qDebug() << "Listening to pipe input:";
timer.start(600);
res = app.exec();
PipeClose(pipe_fds[WRITE]);
PipeClose(pipe_fds[READ]);
return res;
}