File indexing completed on 2026-09-05 09:19:06
0001
0002
0003
0004
0005 #ifndef QIODEVICE_H
0006 #define QIODEVICE_H
0007
0008 #include <QtCore/qglobal.h>
0009 #include <QtCore/qiodevicebase.h>
0010 #ifndef QT_NO_QOBJECT
0011 #include <QtCore/qobject.h>
0012 #else
0013 #include <QtCore/qobjectdefs.h>
0014 #include <QtCore/qscopedpointer.h>
0015 #endif
0016 #include <QtCore/qspan.h>
0017 #include <QtCore/qstring.h>
0018
0019 #ifdef open
0020 #error qiodevice.h must be included before any header file that defines open
0021 #endif
0022
0023 #include <memory>
0024
0025 QT_BEGIN_NAMESPACE
0026
0027
0028 class QByteArray;
0029 class QIODevicePrivate;
0030
0031 class Q_CORE_EXPORT QIODevice
0032 #ifndef QT_NO_QOBJECT
0033 : public QObject,
0034 #else
0035 :
0036 #endif
0037 public QIODeviceBase
0038 {
0039 #ifndef QT_NO_QOBJECT
0040 Q_OBJECT
0041 #endif
0042 public:
0043 QIODevice();
0044 #ifndef QT_NO_QOBJECT
0045 explicit QIODevice(QObject *parent);
0046 #endif
0047 virtual ~QIODevice();
0048
0049 QIODeviceBase::OpenMode openMode() const;
0050
0051 void setTextModeEnabled(bool enabled);
0052 bool isTextModeEnabled() const;
0053
0054 bool isOpen() const;
0055 bool isReadable() const;
0056 bool isWritable() const;
0057 virtual bool isSequential() const;
0058
0059 int readChannelCount() const;
0060 int writeChannelCount() const;
0061 int currentReadChannel() const;
0062 void setCurrentReadChannel(int channel);
0063 int currentWriteChannel() const;
0064 void setCurrentWriteChannel(int channel);
0065
0066 virtual bool open(QIODeviceBase::OpenMode mode);
0067 virtual void close();
0068
0069
0070
0071 virtual qint64 pos() const;
0072 virtual qint64 size() const;
0073 virtual bool seek(qint64 pos);
0074 virtual bool atEnd() const;
0075 virtual bool reset();
0076
0077 virtual qint64 bytesAvailable() const;
0078 virtual qint64 bytesToWrite() const;
0079
0080 qint64 read(char *data, qint64 maxlen);
0081 QByteArray read(qint64 maxlen);
0082 QByteArray readAll();
0083 qint64 readLine(char *data, qint64 maxlen);
0084 QByteArray readLine(qint64 maxlen = 0);
0085 bool readLineInto(QByteArray *result, qint64 maxlen = 0);
0086
0087 QByteArrayView readLineInto(QSpan<char> buffer)
0088 { return readLineInto(as_writable_bytes(buffer)); }
0089 QByteArrayView readLineInto(QSpan<uchar> buffer)
0090 { return readLineInto(as_writable_bytes(buffer)); }
0091 QByteArrayView readLineInto(QSpan<std::byte> buffer);
0092
0093 virtual bool canReadLine() const;
0094
0095 void startTransaction();
0096 void commitTransaction();
0097 void rollbackTransaction();
0098 bool isTransactionStarted() const;
0099
0100 qint64 write(const char *data, qint64 len);
0101 qint64 write(const char *data);
0102 qint64 write(const QByteArray &data);
0103
0104 qint64 peek(char *data, qint64 maxlen);
0105 QByteArray peek(qint64 maxlen);
0106 qint64 skip(qint64 maxSize);
0107
0108 virtual bool waitForReadyRead(int msecs);
0109 virtual bool waitForBytesWritten(int msecs);
0110
0111 void ungetChar(char c);
0112 bool putChar(char c);
0113 bool getChar(char *c);
0114
0115 QString errorString() const;
0116
0117 #ifndef QT_NO_QOBJECT
0118 Q_SIGNALS:
0119 void readyRead();
0120 void channelReadyRead(int channel);
0121 void bytesWritten(qint64 bytes);
0122 void channelBytesWritten(int channel, qint64 bytes);
0123 void aboutToClose();
0124 void readChannelFinished();
0125 #endif
0126
0127 protected:
0128 #ifdef QT_NO_QOBJECT
0129 QIODevice(QIODevicePrivate &dd);
0130 #else
0131 QIODevice(QIODevicePrivate &dd, QObject *parent = nullptr);
0132 #endif
0133 virtual qint64 readData(char *data, qint64 maxlen) = 0;
0134 virtual qint64 readLineData(char *data, qint64 maxlen);
0135 virtual qint64 skipData(qint64 maxSize);
0136 virtual qint64 writeData(const char *data, qint64 len) = 0;
0137
0138 void setOpenMode(QIODeviceBase::OpenMode openMode);
0139
0140 void setErrorString(const QString &errorString);
0141
0142 #ifdef QT_NO_QOBJECT
0143 std::unique_ptr<QIODevicePrivate> d_ptr;
0144 #endif
0145
0146 private:
0147 Q_DECLARE_PRIVATE(QIODevice)
0148 Q_DISABLE_COPY(QIODevice)
0149 };
0150
0151 Q_DECLARE_OPERATORS_FOR_FLAGS(QIODevice::OpenMode)
0152
0153 #if !defined(QT_NO_DEBUG_STREAM)
0154 class QDebug;
0155 Q_CORE_EXPORT QDebug operator<<(QDebug debug, QIODevice::OpenMode modes);
0156 #endif
0157
0158 QT_END_NAMESPACE
0159
0160 #endif