Results 1 to 4 of 4

Thread: QFile::open throws std::bad_alloc for no obvious reason

  1. #1
    Join Date
    Dec 2009
    Posts
    19
    Thanks
    2
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default QFile::open throws std::bad_alloc for no obvious reason

    Constructing QFile object:
    Qt Code:
    1. QFile file("file.ext");
    To copy to clipboard, switch view to plain text mode 
    "file.ext" is present in working directory. Calling file.open(QFile::ReadOnly | QFile::Text) terminates application with error:
    terminate called after throwing an instance of 'std::bad_alloc'
    what(): std::bad_alloc

    This application has requested the Runtime to terminate it in an unusual way.
    Please contact the application's support team for more information.
    The same happens if I try to open embedded resource file.
    It can't be the lack of memory because I have 2 of 4 GB of RAM free, neither the lack of available file handles to acquire, since Windows imposes no limitations on this.
    Any help would be greatly appreciated.

    P.S. The code that tries to open the file is loaded and executed from shared library, but I highly doubt that it can be the case.
    P.P.S. Qt 4.6, Windows XP SP3
    Last edited by nateriver; 28th December 2009 at 16:44. Reason: Forgot to tell qt and windows versions
    "Do be do be do", Frank Sinatra

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QFile::open throws std::bad_alloc for no obvious reason

    If you are running 32-bit Windows, then memory MIGHT be an issue, as even if you have 64GB of RAM, each application only has access to 2GB.

    But I suspect that this is something more difficult to track down, such as memory corruption. Maybe you are corrupting the heap?

  3. #3
    Join Date
    Dec 2009
    Posts
    19
    Thanks
    2
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QFile::open throws std::bad_alloc for no obvious reason

    Still I doubt that it's memory because I've just started developing this application, it only allocates about 100 kb (I'm not taking overhead into account).
    For the same reason it's not likely to be heap corruption, since memory management is very simple in my app thus failproof.

    The only thing that comes in my mind is that it's a bug in Qt, since I've actually seen people with similar problem on several forums.
    "Do be do be do", Frank Sinatra

  4. #4
    Join Date
    Dec 2009
    Posts
    19
    Thanks
    2
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QFile::open throws std::bad_alloc for no obvious reason

    Khm, sorry, the exception was not caused by QFile::open but by some hacky code I wrote myself, so the problem is solved.
    Last edited by wysota; 29th December 2009 at 20:04.
    "Do be do be do", Frank Sinatra

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.