본문 바로가기
QT and Symbian

QT에서 WinAPI SetFilePointer() 함수 대체 방법

by leo21c 2014. 12. 5.

QFile file(fileName); file.open(QFile::ReadOnly); QDataStream in(&file); .... qint64 oldPos = (in.device())->pos(); qint32 nSkipLen = 30; in.skipRawData(nSkipLen); //data를 skip하고 다시 이전 position으로 이동 (in.device())->seek(oldPos); //SetFilePointer()함수의 역활 ....


위와 같이 QDataStream 은 I/O device를 return하는 함수가 있다.
QIODevice Class에는 Pos()와 Seek() 함수가 존재하는데 이 함수들을 이용하면 SetFilePointer()와 같은 방식을 구현할 수 있다.

qint64 QIODevice::pos() const [virtual]

For random-access devices, this function returns the position that data is written to or read from. For sequential devices or closed devices, where there is no concept of a "current position", 0 is returned.

The current read/write position of the device is maintained internally by QIODevice, so reimplementing this function is not necessary. When subclassing QIODevice, use QIODevice::seek() to notify QIODevice about changes in the device position.


bool QIODevice::seek(qint64 pos) [virtual]

For random-access devices, this function sets the current position to pos, returning true on success, or false if an error occurred. For sequential devices, the default behavior is to produce a warning and return false.

When subclassing QIODevice, you must call QIODevice::seek() at the start of your function to ensure integrity with QIODevice's built-in buffer.