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
src_corelib_io_qiodevice.cpp
Go to the documentation of this file.
1
// Copyright (C) 2016 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
4
#
include
<
QProcess
>
5
#
include
<
QIODevice
>
6
#
include
<
QFile
>
7
8
bool
read_example
()
9
{
10
//! [0]
11
QProcess gzip;
12
gzip.start(
"gzip"
, QStringList() <<
"-c"
);
13
if
(!gzip.waitForStarted())
14
return
false
;
15
16
gzip.write(
"uncompressed data"
);
17
18
QByteArray compressed;
19
while
(gzip.waitForReadyRead())
20
compressed += gzip.readAll();
21
//! [0]
22
23
return
true
;
24
}
25
26
class
CustomDevice
:
public
QIODevice
27
{
28
Q_OBJECT
29
public
:
30
qint64
bytesAvailable
()
const
override
;
31
bool
canReadLine
()
const
override
;
32
private
:
33
QByteArray buffer;
34
};
35
36
//! [1]
37
qint64
CustomDevice
::bytesAvailable()
const
38
{
39
return
buffer.size() + QIODevice::bytesAvailable();
40
}
41
//! [1]
42
43
44
void
read_in_buf_example
()
45
{
46
//! [2]
47
QFile file(
"box.txt"
);
48
if
(file.open(QFile::ReadOnly)) {
49
char
buf[1024];
50
qint64 lineLength = file.readLine(buf,
sizeof
(buf));
51
if
(lineLength != -1) {
52
// the line is available in buf
53
}
54
}
55
//! [2]
56
}
57
58
59
//! [3]
60
bool
CustomDevice
::
canReadLine
()
const
61
{
62
return
buffer.contains(
'\n'
) || QIODevice::canReadLine();
63
}
64
//! [3]
65
66
67
//! [method_open]
68
bool
isExeFile
(QFile *file)
69
{
70
//! [method_open]
71
72
if
(
true
)
73
{
74
//! [method_body_0]
75
char
buf[2];
76
if
(file->peek(buf,
sizeof
(buf)) ==
sizeof
(buf))
77
return
(buf[0] ==
'M'
&& buf[1] ==
'Z'
);
78
return
false
;
79
//! [method_body_0]
80
}
81
else
82
{
83
//! [method_body_1]
84
return
file->peek(2) ==
"MZ"
;
85
//! [method_body_1]
86
}
87
88
//! [method_close]
89
}
90
//! [method_close]
CustomDevice
Definition
src_corelib_io_qiodevice.cpp:27
CustomDevice::canReadLine
bool canReadLine() const override
[3]
Definition
src_corelib_io_qiodevice.cpp:60
read_example
bool read_example()
Definition
src_corelib_io_qiodevice.cpp:8
isExeFile
bool isExeFile(QFile *file)
[3]
Definition
src_corelib_io_qiodevice.cpp:68
read_in_buf_example
void read_in_buf_example()
[1]
Definition
src_corelib_io_qiodevice.cpp:44
qtbase
src
corelib
doc
snippets
code
src_corelib_io_qiodevice.cpp
Generated on
for Qt by
1.14.0