Results 1 to 10 of 10

Thread: QDir Subclassing

  1. #1
    Join Date
    Oct 2007
    Location
    Lake Forest, CA, USA
    Posts
    132
    Thanks
    10
    Thanked 27 Times in 22 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Question QDir Subclassing

    Hi everyone.
    I'm looking for some information how QDir works.
    I need to implement direct disk reading and filesystem browsing for FAT partitions and accessing to NTFS partitions through WinAPI.
    So, my first question is, is there any reason in subclassing QDir or it'll be better to make my own new class?
    Second one, which QDir's methods need to be implemented? For example, such methods like absolutePath (), makeAbsolute () or canonicalPath () rely on internal data (if yes, which? ) or always calling system functions? What about sorting? Will it work, if I provide correct QFileInfo objects? And how should I provide them?

    Sorry, if there are too many mistakes, English isn't my motherlanguage and I haven't got enough practice.
    Thanks for answers.

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QDir Subclassing

    I need to implement direct disk reading and filesystem browsing for FAT partitions and accessing to NTFS partitions through WinAPI.
    If you need more than QDir can offer then why don't you write your own class?
    You should inherit QAbstractFileEngine. QDir is not meant for subclassing.

    To see what WinAPI functions QDir uses you can always take a look at its sources.

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

    Oleg (29th October 2007)

  4. #3
    Join Date
    Oct 2007
    Location
    Lake Forest, CA, USA
    Posts
    132
    Thanks
    10
    Thanked 27 Times in 22 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: QDir Subclassing

    Thanks a lot, I have't noticed QAbstractFileEngine class.

    As I've understood I should implement my own QAbstractFileEngine and QAbstractFileEngineHandler classes. And one question.

    Documentation:
    When you open a file, Qt chooses a suitable file engine by passing the file name from QFile or QDir through an internal list of registered file engine handlers.
    I need access to whole file system, so I should use my own file name format, like fat:c:\windows or ntfs:d:\folder? Or something else? So, how can I say that some filesystem path must be processed using my file engine?

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QDir Subclassing

    Something like that. But why do you do it in the first place? Can't you access the files with the regular file system access (QDir, QFile, ls, dir...)?

  6. #5
    Join Date
    Oct 2007
    Location
    Lake Forest, CA, USA
    Posts
    132
    Thanks
    10
    Thanked 27 Times in 22 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: QDir Subclassing

    Of course, I can
    But it is my course work in the university. I should implement file manager with direct disk I/O for FAT FS and WinAPI interface for NTFS.
    So, I'm looking for the simplest way.

    In
    virtual QAbstractFileEngine * create ( const QString & fileName ) const = 0
    I check if fileName has my prefix and if so I return my new file engine. Is it right?
    And in this way I can use all standart classes for filesystem access, like QDir, QDirModel, etc, without change, can't I?

  7. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QDir Subclassing

    I don't think this is the simplest way... Well, of course you CAN do it this way, but modifying the FS structures behind the system's back (I mean when the devices are mounted) is dangerous. As long as your file manager is read only you should be relatively safe, at least on uni-processor system. If you are on a unix like system, umounting the appropriate file systems is a must and then you can use the Qt abstract file engine. If you are on Windows (and I guess this is the case), you are walking on a thin line here, so think twice before doing anything.

  8. #7
    Join Date
    Oct 2007
    Location
    Lake Forest, CA, USA
    Posts
    132
    Thanks
    10
    Thanked 27 Times in 22 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: QDir Subclassing

    Of course, it's dangerous
    But as I've said this is only an educational task and my program will never be used in the real life. So, I'm not afraid of crashing my virtual machine.

    Thanks for answers.
    Last edited by Oleg; 29th October 2007 at 13:32. Reason: spelling error

  9. #8
    Join Date
    Oct 2007
    Location
    Lake Forest, CA, USA
    Posts
    132
    Thanks
    10
    Thanked 27 Times in 22 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: QDir Subclassing

    I have a problem while implementing my own QAbstractFileEngine.

    So, I have a new class:
    Qt Code:
    1. class cwNTFSFileEngine : public QAbstractFileEngine
    2. {
    3. public:
    4. qint64 size() const;
    5. bool isSequential() const;
    6. bool isRelativePath() const;
    7. QStringList entryList ( QDir::Filters filters, const QStringList &filterNames ) const;
    8. FileFlags fileFlags ( FileFlags type = FileInfoAll ) const;
    9. QString fileName ( FileName file = DefaultName ) const;
    10. QDateTime fileTime ( FileTime time ) const;
    11. Iterator *beginEntryList ( QDir::Filters filters, const QStringList &filterNames );
    12. Iterator *endEntryList();
    13. // Others methods are implemented, but return error values
    14. };
    To copy to clipboard, switch view to plain text mode 

    And in
    Qt Code:
    1. FileFlags cwNTFSFileEngine::fileFlags ( FileFlags type = FileInfoAll ) const
    2. {
    3. // File type detection
    4. }
    To copy to clipboard, switch view to plain text mode 

    I get an error:
    cwntfsfileengine.cpp:18: error: `FileFlags' does not name a type

    I think there's a stupid bug in my, but I can't resolve it.
    Oleg Shparber

  10. #9
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QDir Subclassing

    Prefix it with "QAbstractFileEngine::"
    Qt Code:
    1. QAbstractFileEngine::FileFlags cwNTFSFileEngine::fileFlags ( QAbstractFileEngine::FileFlags type = FileInfoAll ) const
    2. {
    3. // File type detection
    4. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  11. The following user says thank you to jpn for this useful post:

    Oleg (31st October 2007)

  12. #10
    Join Date
    Oct 2007
    Location
    Lake Forest, CA, USA
    Posts
    132
    Thanks
    10
    Thanked 27 Times in 22 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: QDir Subclassing

    Thanks for reply.

    The correct solution:
    Qt Code:
    1. QAbstractFileEngine::FileFlags cwNTFSFileEngine::fileFlags ( FileFlags type ) const
    2. {
    3. // code
    4. }
    To copy to clipboard, switch view to plain text mode 
    Oleg Shparber

Similar Threads

  1. Is it me or QDir?
    By Morea in forum Qt Programming
    Replies: 1
    Last Post: 29th June 2007, 23:06
  2. Problem with QTreeWidget after subclassing
    By steve918 in forum Qt Programming
    Replies: 2
    Last Post: 28th July 2006, 18:51
  3. Problem in SubClassing QTableItem.
    By sumsin in forum Qt Programming
    Replies: 3
    Last Post: 22nd May 2006, 10:21
  4. Subclassing QScrollView
    By sumsin in forum Qt Programming
    Replies: 13
    Last Post: 16th March 2006, 14:20
  5. How to explicitely delete a QDir?
    By alan in forum Newbie
    Replies: 2
    Last Post: 13th February 2006, 17:48

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.