Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
stdinlistener.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
5
6#include "tracer.h"
7
8#include <stdio.h>
9
10QT_BEGIN_NAMESPACE
11
12StdInListener::StdInListener(QObject *parent)
13 : QSocketNotifier(fileno(stdin), QSocketNotifier::Read, parent)
14{
16 connect(this, &QSocketNotifier::activated,
17 this, &StdInListener::receivedData);
18}
19
24
25void StdInListener::start()
26{
27 setEnabled(true);
28}
29
30void StdInListener::receivedData()
31{
33 QByteArray ba;
34 while (true) {
35 const int c = getc(stdin);
36 if (c == EOF) {
37 setEnabled(false);
38 break;
39 }
40 if (c == '\0')
41 break;
42 if (c)
43 ba.append(char(c));
44 if (c == '\n')
45 break;
46 }
47 emit receivedCommand(QString::fromLocal8Bit(ba));
48}
49
50QT_END_NAMESPACE
#define TRACE_OBJ
Definition tracer.h:34