Results 1 to 2 of 2

Thread: How to properly subclass QIODevice -- understanding the docs

  1. #1
    Join Date
    Jan 2010
    Location
    Perth, Australia
    Posts
    37
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How to properly subclass QIODevice -- understanding the docs

    I'd like to learn how to correctly subclass a QIODevice, and I'm not sure how to interpret some sentences in the Class Reference page:

    Under pos()
    "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."
    Before reading this, I thought that seek() was to be called externally (i.e. outside the class/object) to tell the (random-access) device to move its internal pointer.

    How do I use seek() to "notify QIODevice about changes"? Am I to call seek() internally as well (from member functions), and then use only seek() (and no other technique) to manipulate my internal pointer to the data?


    Under seek()
    "When subclassing QIODevice, you must call QIODevice::seek() at the start of your function to ensure integrity with QIODevice's built-in buffer."
    It's not clear to me: The start of which function? The external function that just opened my device?


    Thanks in advance for your guidance!

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to properly subclass QIODevice -- understanding the docs

    QIODevice keeps a track of the number of bytes read (i.e. the pos()) and allows you to skip about with seek(). If your subclass implements a seek() override that does something special, or some other function that affects the current position, it should call QIODevice::seek() so the base class is updated properly. That is:
    Qt Code:
    1. bool MyIODevice::seek ( qint64 pos ) {
    2. QIODevice::seek(pos);
    3. // Do your sub-class magic with pos here
    4. // e.g. if you need to issue commands to hardware to rewind to the corresponding position
    5. }
    To copy to clipboard, switch view to plain text mode 
    If you do not override the base class seek() then you don't need to do anything special.

  3. The following user says thank you to ChrisW67 for this useful post:

    hackerNovitiate (2nd January 2012)

Similar Threads

  1. QHelpCollection xml docs
    By johnmauer in forum Newbie
    Replies: 0
    Last Post: 17th December 2010, 19:01
  2. template to retrieve QIODevice subclass
    By onil in forum Qt Programming
    Replies: 6
    Last Post: 25th June 2010, 17:54
  3. Replies: 0
    Last Post: 28th October 2009, 12:20
  4. doxygen config like qt docs
    By danadam in forum General Discussion
    Replies: 1
    Last Post: 3rd September 2006, 19:10
  5. Problem with the Qt docs
    By Morea in forum Qt Programming
    Replies: 6
    Last Post: 21st February 2006, 13:11

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.