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
4
#
include
"stdinlistener.h"
5
6
#
include
"tracer.h"
7
8
#
include
<
stdio
.
h
>
9
10
QT_BEGIN_NAMESPACE
11
12
StdInListener::StdInListener(QObject *parent)
13
: QSocketNotifier(fileno(stdin), QSocketNotifier::Read, parent)
14
{
15
TRACE_OBJ
16
connect(
this
, &QSocketNotifier::activated,
17
this
, &StdInListener::receivedData);
18
}
19
20
StdInListener
::~
StdInListener
()
21
{
22
TRACE_OBJ
23
}
24
25
void
StdInListener
::start()
26
{
27
setEnabled(
true
);
28
}
29
30
void
StdInListener
::receivedData()
31
{
32
TRACE_OBJ
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
50
QT_END_NAMESPACE
StdInListener
Definition
stdinlistener.h:12
StdInListener::~StdInListener
~StdInListener()
Definition
stdinlistener.cpp:20
TRACE_OBJ
#define TRACE_OBJ
Definition
tracer.h:34
qttools
src
assistant
assistant
stdinlistener.cpp
Generated on Thu Nov 14 2024 00:53:11 for Qt by
1.12.0