QFile::open throws std::bad_alloc for no obvious reason
Constructing QFile object:
"file.ext" is present in working directory. Calling file.open(QFile::ReadOnly | QFile::Text) terminates application with error:
Quote:
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
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?
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.
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.