[Qt-interest] QFile seeking from SEEK_SET ? ( fseek like function )
Constantin Makshin
cmakshin at gmail.com
Wed Sep 15 21:18:10 CEST 2010
Yes, the documentation may be a bit confusing. However, QFile::seek()
has the same behavior as QIODevice::seek(); here is a line from the
QFile::seek() function code:
if (!d->fileEngine->seek(off) || !QIODevice::seek(off)) {
Also, "offset" doesn't mean the position is relative to the current
one. Offset can be relative to anything, including the beginning of
the file. :)
On Wed, Sep 15, 2010 at 3:33 PM, Francisco Gonzalez Morell
<gzmorell at gmail.com> wrote:
> On Martes 14 Septiembre 2010 20:05:40 Constantin Makshin escribió:
>> Please re-read the documentation — nothing says it sets position relative
>> to the current one. What has caused you to make that assumption?
>>
> From QFile Doc
> /*
> bool QFile::seek ( qint64 off ) [virtual]
> Reimplemented from QIODevice::seek().
> */
>
> From QIODevice Doc
> /*
> 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 do nothing 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. The base
> implementation always returns true.
> */
>
> The QFile Docs tells that it is reimplemented.
> The function is declared: bool QFile::seek (qint64 off) [virtual]
> The word "off" instead of "pos" seems to indicate that the parameter is an
> offset not an absolute position.
> At least in the platform I use it is an absolute position.
> Perhaps doc should say:
> bool QFile::seed (qint64 pos) [virtual]
>
> Francisco
>
>> On Tuesday 14 September 2010 07:01:39 Aaron Lewis wrote:
>> > On 09/14/2010 10:42 AM, Malyushytsky, Alex wrote:
>> > > It helps to check base class documentation: bool QIODevice::seek (
>> > > qint64 pos )
>> >
>> > Thanks for quick reply ;-)
>> >
>> > QFile *fp = new QFile();
>> >
>> > Blabla ...
>> >
>> > fp->seek( 7 - fp->pos() );
>> >
>> >
>> > Yep , it works for negative numbers , but was it supposed to be like
>> > that ?
>> >
>> > Thanks.
More information about the Qt-interest-old
mailing list