⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qiodevice.cpp

📁 Trolltech公司发布的图形界面操作系统。可在qt-embedded-2.3.10平台上编译为嵌入式图形界面操作系统。
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/************************************************************************ Copyright (C) 2000-2005 Trolltech AS.  All rights reserved.**** This file is part of the Qtopia Environment.** ** This program is free software; you can redistribute it and/or modify it** under the terms of the GNU General Public License as published by the** Free Software Foundation; either version 2 of the License, or (at your** option) any later version.** ** A copy of the GNU GPL license version 2 is included in this package as ** LICENSE.GPL.**** This program is distributed in the hope that it will be useful, but** WITHOUT ANY WARRANTY; without even the implied warranty of** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ** See the GNU General Public License for more details.**** In addition, as a special exception Trolltech gives permission to link** the code of this program with Qtopia applications copyrighted, developed** and distributed by Trolltech under the terms of the Qtopia Personal Use** License Agreement. You must comply with the GNU General Public License** in all respects for all of the code used other than the applications** licensed under the Qtopia Personal Use License Agreement. If you modify** this file, you may extend this exception to your version of the file,** but you are not obligated to do so. If you do not wish to do so, delete** this exception statement from your version.** ** See http://www.trolltech.com/gpl/ for GPL licensing information.**** Contact info@trolltech.com if any conditions of this licensing are** not clear to you.************************************************************************/#include "qiodevice.h"/*!    \class QIODevice qiodevice.h    \reentrant    \brief The QIODevice class is the base class of I/O devices.    \ingroup io    An I/O device represents a medium that one can read bytes from    and/or write bytes to. The QIODevice class is the abstract    superclass of all such devices; classes such as QFile, QBuffer and    QSocket inherit QIODevice and implement virtual functions such as    write() appropriately.    Although applications sometimes use QIODevice directly, it is    usually better to use QTextStream and QDataStream, which provide    stream operations on any QIODevice subclass. QTextStream provides    text-oriented stream functionality (for human-readable ASCII    files, for example), whereas QDataStream deals with binary data in    a totally platform-independent manner.    The public member functions in QIODevice roughly fall into two    groups: the action functions and the state access functions. The    most important action functions are:    \list    \i  open() opens a device for reading and/or writing, depending on    the mode argument.    \i  close() closes the device and tidies up (e.g. flushes buffered    data)    \i  readBlock() reads a block of data from the device.    \i  writeBlock() writes a block of data to the device.    \i  readLine() reads a line (of text, usually) from the device.    \i  flush() ensures that all buffered data are written to the real device.    \endlist    There are also some other, less used, action functions:    \list    \i  getch() reads a single character.    \i  ungetch() forgets the last call to getch(), if possible.    \i  putch() writes a single character.    \i  size() returns the size of the device, if there is one.    \i  at() returns the current read/write pointer's position, if there    is one for this device, or it moves the pointer if given an offset.    \i  atEnd() indicates whether there is more to read, if this is    meaningful for this device.    \i  reset() moves the read/write pointer to the start of the    device, if that is possible for this device.    \endlist    The state access are all "get" functions. The QIODevice subclass    calls setState() to update the state, and simple access functions    tell the user of the device what the device's state is. Here are    the settings, and their associated access functions:    \list    \i  Access type. Some devices are direct access (it is possible    to read/write anywhere), whereas others are sequential. QIODevice    provides the access functions (isDirectAccess(),    isSequentialAccess(), and isCombinedAccess()) to tell users what a    given I/O device supports.    \i  Buffering. Some devices are accessed in raw mode, whereas    others are buffered. Buffering usually provides greater    efficiency, particularly for small read/write operations.    isBuffered() tells the user whether a given device is buffered.    (This can often be set by the application in the call to open().)    \i  Synchronicity. Synchronous devices work immediately (for    example, files). When you read from a file, the file delivers its    data straight away. Other kinds of device, such as a socket    connected to a HTTP server, may not deliver the data until seconds    after you ask to read it. isSynchronous() and isAsynchronous()    tell the user how this device operates.    \i  CR/LF translation. For simplicity, applications often like to    see just a single CR/LF style, and QIODevice subclasses can    provide this. isTranslated() returns TRUE if this object    translates CR/LF to just LF. (This can often be set by the    application in the call to open().)    \i  Permissions. Some files cannot be written. For example,    isReadable(), isWritable() and isReadWrite() tell the application    whether it can read from and write to a given device. (This can    often be set by the application in the call to open().)    \i  Finally, isOpen() returns TRUE if the device is open, i.e.    after an open() call.    \endlist    QIODevice provides numerous pure virtual functions that you need    to implement when subclassing it. Here is a skeleton subclass with    all the members you are sure to need and some that you will    probably need:    \code    class MyDevice : public QIODevice    {    public:	MyDevice();	~MyDevice();	bool open( int mode );	void close();	void flush();	uint size() const;	int  at() const;	// non-pure virtual	bool at( int );		// non-pure virtual	bool atEnd() const;	// non-pure virtual	int readBlock( char *data, uint maxlen );	int writeBlock( const char *data, uint len );	int readLine( char *data, uint maxlen );	int getch();	int putch( int );	int ungetch( int );    };    \endcode    The three non-pure virtual functions need not be reimplemented for    sequential devices.    \sa QDataStream, QTextStream*//*!    \enum QIODevice::Offset    The offset within the device.*//*!    Constructs an I/O device.*/QIODevice::QIODevice(){    ioMode = 0;					// initial mode    ioSt = IO_Ok;    ioIndex = 0;}/*!    Destroys the I/O device.*/QIODevice::~QIODevice(){}/*!    \fn int QIODevice::flags() const    Returns the current I/O device flags setting.    Flags consists of mode flags and state flags.    \sa mode(), state()*//*!    \fn int QIODevice::mode() const    Returns bits OR'ed together that specify the current operation    mode.    These are the flags that were given to the open() function.    The flags are \c IO_ReadOnly, \c IO_WriteOnly, \c IO_ReadWrite,    \c IO_Append, \c IO_Truncate and \c IO_Translate.*//*!    \fn int QIODevice::state() const    Returns bits OR'ed together that specify the current state.    The flags are: \c IO_Open.    Subclasses may define additional flags.*//*!    \fn bool QIODevice::isDirectAccess() const    Returns TRUE if the I/O device is a direct access device;    otherwise returns FALSE, i.e. if the device is a sequential access    device.    \sa isSequentialAccess()*//*!    \fn bool QIODevice::isSequentialAccess() const    Returns TRUE if the device is a sequential access device;    otherwise returns FALSE, i.e. if the device is a direct access    device.    Operations involving size() and at(int) are not valid on    sequential devices.    \sa isDirectAccess()*//*!    \fn bool QIODevice::isCombinedAccess() const    Returns TRUE if the I/O device is a combined access (both direct    and sequential) device; otherwise returns FALSE.    This access method is currently not in use.*//*!    \fn bool QIODevice::isBuffered() const    Returns TRUE if the I/O device is a buffered device; otherwise    returns FALSE, i.e. the device is a raw device.    \sa isRaw()*//*!    \fn bool QIODevice::isRaw() const    Returns TRUE if the device is a raw device; otherwise returns    FALSE, i.e. if the device is a buffered device.    \sa isBuffered()*//*!    \fn bool QIODevice::isSynchronous() const    Returns TRUE if the I/O device is a synchronous device; otherwise    returns FALSE, i.e. the device is an asynchronous device.    \sa isAsynchronous()*//*!    \fn bool QIODevice::isAsynchronous() const    Returns TRUE if the device is an asynchronous device; otherwise    returns FALSE, i.e. if the device is a synchronous device.    This mode is currently not in use.    \sa isSynchronous()*//*!    \fn bool QIODevice::isTranslated() const    Returns TRUE if the I/O device translates carriage-return and    linefeed characters; otherwise returns FALSE.    A QFile is translated if it is opened with the \c IO_Translate    mode flag.*//*!    \fn bool QIODevice::isReadable() const    Returns TRUE if the I/O device was opened using \c IO_ReadOnly or    \c IO_ReadWrite mode; otherwise returns FALSE.    \sa isWritable(), isReadWrite()*//*!    \fn bool QIODevice::isWritable() const    Returns TRUE if the I/O device was opened using \c IO_WriteOnly or    \c IO_ReadWrite mode; otherwise returns FALSE.    \sa isReadable(), isReadWrite()*//*!    \fn bool QIODevice::isReadWrite() const    Returns TRUE if the I/O device was opened using \c IO_ReadWrite    mode; otherwise returns FALSE.    \sa isReadable(), isWritable()*//*!    \fn bool QIODevice::isInactive() const    Returns TRUE if the I/O device state is 0, i.e. the device is not    open; otherwise returns FALSE.    \sa isOpen()*//*!    \fn bool QIODevice::isOpen() const    Returns TRUE if the I/O device has been opened; otherwise returns    FALSE.    \sa isInactive()*//*!    \fn int QIODevice::status() const    Returns the I/O device status.    The I/O device status returns an error code. If open() returns    FALSE or readBlock() or writeBlock() return -1, this function can    be called to find out the reason why the operation failed.    \keyword IO_Ok

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -