Results 1 to 4 of 4

Thread: QFileDevice::map() returns "Access is denied" after file resize

  1. #1
    Join Date
    Nov 2013
    Posts
    4
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default QFileDevice::map() returns "Access is denied" after file resize

    Hello everyone,

    I'm using a memory mapped file through a QFile object and its map() method. Works like a charm so far -- until I'm doing a resize() of the file. After that, map() always results in "Access is denied".

    Maybe I'm doing something wrong, but I've tried every conceivable combination of unmap(), close(), open(), resize(), flush() I could think of. I know that the resize works, since size() reports the correct size after the resize and its size on disk is also correct. unmap() returns true. open() returns true. resize() returns true. But as soon as I want to map() the whole file (we're talking 128kB here), I get an error. I can, however, map() to the original file size... Cache problem or something?! No idea what I'm doing wrong.

    Heres the method with which I try to extend the mmap'd file:

    Qt Code:
    1. void xxx::Extend()
    2. {
    3. file.unmap(mmap);
    4.  
    5. file.resize( file.size() + PAGESIZE );
    6.  
    7. // Doesn't seem to be necessary
    8. file.close();
    9. file.open(QIODevice::ReadWrite);
    10.  
    11. // After this, mmap == nullptr, except parm size of map() is <= original file size
    12. mmap = file.map(0, file.size());
    13.  
    14. // This prints "Access is denied"
    15. qDebug() << file.errorString();
    16. }
    To copy to clipboard, switch view to plain text mode 


    Thanks a lot in advance and best regards!


    Edit: OS is Windows 7 64bit, Qt 5.1.1 and MinGW 4.8.0
    Last edited by Jansemon; 5th November 2013 at 16:41.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QFileDevice::map() returns "Access is denied" after file resize

    Have you tried mapping the old size again? I.e. maybe the new size is beyond some kind of limit?

    Alternatively try to open+map using a local QFile instance, to check if some kind of internal state of "file" could be at fault.

    Cheers,
    _

  3. #3
    Join Date
    Nov 2013
    Posts
    4
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QFileDevice::map() returns "Access is denied" after file resize

    Thanks for your reply.

    As stated, that is exactly what works - I can map the old size (64kB), but not oldsize + 1 (after resizing it to 128kB)... I'll try creating a new instance of QFile and try it again.


    Added after 15 minutes:


    Hm... ok, when I delete the previous QFile object and create a new one (after I resized the old one) it works. Is this by design or a bug? Because if it's the former, maybe some notice in the docs would be nice.
    Last edited by Jansemon; 5th November 2013 at 16:55.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QFileDevice::map() returns "Access is denied" after file resize

    Sounds like a bug to me.

    Cheers,
    _

Similar Threads

  1. Replies: 5
    Last Post: 15th August 2014, 04:04
  2. libpng "permission denied"
    By RolandHughes in forum Qt Programming
    Replies: 1
    Last Post: 19th February 2013, 18:29
  3. Replies: 3
    Last Post: 15th February 2010, 18:27
  4. Replies: 3
    Last Post: 25th August 2009, 14:03
  5. QLocale::system().name() returns "C" instead of "de"
    By momesana in forum Qt Programming
    Replies: 1
    Last Post: 18th February 2008, 15:59

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.