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
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
26class CustomDevice : public QIODevice
27{
29public:
31 bool canReadLine() const override;
32private:
33 QByteArray buffer;
34};
35
36//! [1]
37qint64 CustomDevice::bytesAvailable() const
38{
39 return buffer.size() + QIODevice::bytesAvailable();
40}
41//! [1]
42
43
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]
61{
62 return buffer.contains('\n') || QIODevice::canReadLine();
63}
64//! [3]
65
66
67//! [method_open]
68bool 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]
bool canReadLine() const override
[3]
bool read_example()
bool isExeFile(QFile *file)
[3]
void read_in_buf_example()
[1]