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
qiodevice.h
Go to the documentation of this file.
1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:header-decls-only
4
5#ifndef QIODEVICE_H
6#define QIODEVICE_H
7
8#include <QtCore/qdeadlinetimer.h>
9#include <QtCore/qiodevicebase.h>
10#ifndef QT_NO_QOBJECT
11#include <QtCore/qobject.h>
12#else
13#include <QtCore/qobjectdefs.h>
14#include <QtCore/qscopedpointer.h>
15#endif
16#include <QtCore/qspan.h>
17#include <QtCore/qstring.h>
18
19#ifdef open
20#error qiodevice.h must be included before any header file that defines open
21#endif
22
23#include <memory>
24
25QT_BEGIN_NAMESPACE
26
27
28class QByteArray;
29class QIODevicePrivate;
30
31class Q_CORE_EXPORT QIODevice
32#ifndef QT_NO_QOBJECT
33 : public QObject,
34#else
35 :
36#endif
37 public QIODeviceBase
38{
39#ifndef QT_NO_QOBJECT
40 Q_OBJECT
41#endif
42protected:
43 struct WaitForVirtualParametersChanged {
44 bool value;
45 Q_IMPLICIT constexpr WaitForVirtualParametersChanged(bool b) : value(b) {}
46 constexpr Q_IMPLICIT operator bool() const noexcept { return value; }
47 constexpr bool operator!() const noexcept { return !value; }
48 };
49
50public:
51 QIODevice();
52#ifndef QT_NO_QOBJECT
53 explicit QIODevice(QObject *parent);
54#endif
55 virtual ~QIODevice();
56
57 QIODeviceBase::OpenMode openMode() const;
58
59 void setTextModeEnabled(bool enabled);
60 bool isTextModeEnabled() const;
61
62 bool isOpen() const;
63 bool isReadable() const;
64 bool isWritable() const;
65 virtual bool isSequential() const;
66
67 int readChannelCount() const;
68 int writeChannelCount() const;
69 int currentReadChannel() const;
70 void setCurrentReadChannel(int channel);
71 int currentWriteChannel() const;
72 void setCurrentWriteChannel(int channel);
73
74 virtual bool open(QIODeviceBase::OpenMode mode);
75 virtual void close();
76
77 // ### Qt 7 - QTBUG-76492: pos() and seek() should not be virtual, and
78 // ### seek() should call a virtual seekData() function.
79 virtual qint64 pos() const;
80 virtual qint64 size() const;
81 virtual bool seek(qint64 pos);
82 virtual bool atEnd() const;
83 virtual bool reset();
84
85 virtual qint64 bytesAvailable() const;
86 virtual qint64 bytesToWrite() const;
87
88 qint64 read(char *data, qint64 maxlen);
89 QByteArray read(qint64 maxlen);
90 QByteArray readAll();
91 qint64 readLine(char *data, qint64 maxlen);
92 QByteArray readLine(qint64 maxlen = 0);
93 bool readLineInto(QByteArray *result, qint64 maxlen = 0);
94
95 QByteArrayView readLineInto(QSpan<char> buffer)
96 { return readLineInto(as_writable_bytes(buffer)); }
97 QByteArrayView readLineInto(QSpan<uchar> buffer)
98 { return readLineInto(as_writable_bytes(buffer)); }
99 QByteArrayView readLineInto(QSpan<std::byte> buffer);
100
101 virtual bool canReadLine() const;
102
103 void startTransaction();
104 void commitTransaction();
105 void rollbackTransaction();
106 bool isTransactionStarted() const;
107
108 qint64 write(const char *data, qint64 len);
109 qint64 write(const char *data);
110 qint64 write(const QByteArray &data);
111
112 qint64 peek(char *data, qint64 maxlen);
113 QByteArray peek(qint64 maxlen);
114 qint64 skip(qint64 maxSize);
115
116 QT7_ONLY(virtual) bool waitForReadyRead(QDeadlineTimer deadline);
117 QT7_ONLY(virtual) bool waitForBytesWritten(QDeadlineTimer deadline);
118#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0) && !defined(QT_BOOTSTRAPPED)
119 virtual bool waitForReadyRead(int msecs);
120 virtual bool waitForBytesWritten(int msecs);
121#else
122 WaitForVirtualParametersChanged waitForReadyRead(int msecs)
123 { return waitForReadyRead(QDeadlineTimer(msecs)); }
124 WaitForVirtualParametersChanged waitForBytesWritten(int msecs)
125 { return waitForBytesWritten(QDeadlineTimer(msecs)); }
126#endif
127
128 void ungetChar(char c);
129 bool putChar(char c);
130 bool getChar(char *c);
131
132 QString errorString() const;
133
134#ifndef QT_NO_QOBJECT
135Q_SIGNALS:
136 void readyRead();
137 void channelReadyRead(int channel);
138 void bytesWritten(qint64 bytes);
139 void channelBytesWritten(int channel, qint64 bytes);
140 void aboutToClose();
141 void readChannelFinished();
142#endif
143
144protected:
145#ifdef QT_NO_QOBJECT
146 QIODevice(QIODevicePrivate &dd);
147#else
148 QIODevice(QIODevicePrivate &dd, QObject *parent = nullptr);
149#endif
150 virtual qint64 readData(char *data, qint64 maxlen) = 0;
151 virtual qint64 readLineData(char *data, qint64 maxlen);
152 virtual qint64 skipData(qint64 maxSize);
153 virtual qint64 writeData(const char *data, qint64 len) = 0;
154
155 void setOpenMode(QIODeviceBase::OpenMode openMode);
156
157 void setErrorString(const QString &errorString);
158
159#ifdef QT_NO_QOBJECT
160 std::unique_ptr<QIODevicePrivate> d_ptr;
161#endif
162
163private:
164 Q_DECLARE_PRIVATE(QIODevice)
165 Q_DISABLE_COPY(QIODevice)
166};
167
168Q_DECLARE_OPERATORS_FOR_FLAGS(QIODevice::OpenMode)
169
170#if !defined(QT_NO_DEBUG_STREAM)
171class QDebug;
172Q_CORE_EXPORT QDebug operator<<(QDebug debug, QIODevice::OpenMode modes);
173#endif
174
175QT_END_NAMESPACE
176
177#endif // QIODEVICE_H
\inmodule QtCore \reentrant
Definition qiodevice.h:38
ImageOption
This enum describes the different options supported by QImageIOHandler.
The QJp2Handler class provides support for reading and writing JPEG 2000 image files with the Qt plug...
~QJp2Handler()
Destructor for QJp2Handler.
QJp2Handler()
Constructs an instance of QJp2Handler.
static bool canRead(QIODevice *iod, QByteArray *subType)
Verifies if some values (magic bytes) are set as expected in the header of the file.
void setOption(ImageOption option, const QVariant &value) override
The JPEG 2000 handler supports two options.
bool write(const QImage &image) override
\reimp
bool read(QImage *image) override
\reimp
bool supportsOption(ImageOption option) const override
This function will return true if option is set to either QImageIOHandler::Quality or QImageIOHandler...
QVariant option(ImageOption option) const override
Get the value associated with option.
bool canRead() const override
\reimp
QImageIOHandler * create(QIODevice *device, const QByteArray &format=QByteArray()) const override
Creates and returns a QImageIOHandler subclass, with device and format set.
Definition main.cpp:46
Combined button and popup list for selecting options.
Q_CORE_EXPORT QDebug operator<<(QDebug debug, QDir::Filters filters)
Definition qdir.cpp:2620