Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
file.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
<
QFile
>
5
#
include
<
QTextStream
>
6
7
static
void
process_line
(
const
QByteArray &)
8
{
9
}
10
11
static
void
process_line
(
const
QString &)
12
{
13
}
14
15
static
void
noStream_snippet
()
16
{
17
//! [0]
18
QFile file(
"in.txt"
);
19
if
(!file.open(QIODevice::ReadOnly | QIODevice::Text))
20
return
;
21
22
while
(!file.atEnd()) {
23
QByteArray line = file.readLine();
24
process_line(line);
25
}
26
//! [0]
27
}
28
29
static
void
readTextStream_snippet
()
30
{
31
//! [1]
32
QFile file(
"in.txt"
);
33
if
(!file.open(QIODevice::ReadOnly | QIODevice::Text))
34
return
;
35
36
QTextStream in(&file);
37
while
(!in.atEnd()) {
38
QString line = in.readLine();
39
process_line(line);
40
}
41
//! [1]
42
}
43
44
static
void
writeTextStream_snippet
()
45
{
46
//! [2]
47
QFile file(
"out.txt"
);
48
if
(!file.open(QIODevice::WriteOnly | QIODevice::Text))
49
return
;
50
51
QTextStream out(&file);
52
out <<
"The magic number is: "
<< 49 <<
"\n"
;
53
//! [2]
54
}
55
56
static
void
writeDataStream_snippet
()
57
{
58
QFile file(
"out.dat"
);
59
if
(!file.open(QIODevice::WriteOnly))
60
return
;
61
62
QDataStream out(&file);
63
out <<
"The magic number is: "
<< 49 <<
"\n"
;
64
}
65
66
static
void
readRegularEmptyFile_snippet
()
67
{
68
//! [3]
69
QFile file(
"/proc/modules"
);
70
if
(!file.open(QIODevice::ReadOnly | QIODevice::Text))
71
return
;
72
73
QTextStream in(&file);
74
QString line = in.readLine();
75
while
(!line.isNull()) {
76
process_line(line);
77
line = in.readLine();
78
}
79
//! [3]
80
}
writeTextStream_snippet
static void writeTextStream_snippet()
Definition
file.cpp:44
noStream_snippet
static void noStream_snippet()
Definition
file.cpp:15
writeDataStream_snippet
static void writeDataStream_snippet()
Definition
file.cpp:56
readRegularEmptyFile_snippet
static void readRegularEmptyFile_snippet()
Definition
file.cpp:66
readTextStream_snippet
static void readTextStream_snippet()
Definition
file.cpp:29
process_line
static void process_line(const QByteArray &)
Definition
file.cpp:7
qtbase
src
corelib
doc
snippets
file
file.cpp
Generated on
for Qt by
1.18.0