Corrupted heap space using QtXmld4.dll (VS 2010)
to make a long story short, here is the code:
int main(int argc, char *argv)
int a, b;
QDomDocument doc( "appsettings" );
if( !f.open( QIODevice::ReadOnly ) )
if( !doc.setContent( &f, &errorMsg, &a, &b ) ) //here is where I get the exception
linking libraries : qtmaind.lib, QtCored4.lib, QtXmld4.lib
and, th callstack looks like:
[Frames below may be incorrect and/or missing, no symbols loaded for ntdll.dll]
QtXmld4.dll!_unlock(int locknum) Line 375 C
QtXmld4.dll!_free_dbg(void * pUserData, int nBlockUse) Line 1270 + 0x7 bytes C++
QtXmld4.dll!_CrtIsValidHeapPointer(const void * pUserData) Line 2036 C++
QtXmld4.dll!_free_dbg_nolock(void * pUserData, int nBlockUse) Line 1322 + 0x9 bytes C++
QtXmld4.dll!_free_dbg(void * pUserData, int nBlockUse) Line 1265 + 0xd bytes C++
QtXmld4.dll!operator delete(void * pUserData) Line 54 + 0x10 bytes C++
QtXmld4.dll!QTextDecoder::`scalar deleting destructor'() + 0x21 bytes C++
QtXmld4.dll!QXmlInputSource::~QXmlInputSource() Line 1357 + 0x22 bytes C++
QtXmld4.dll!QDomDocument::setContent(QIODevice * dev, bool namespaceProcessing, QString * errorMsg, int * errorLine, int * errorColumn) Line 6755 + 0x31 bytes C++
QtXmld4.dll!QDomDocument::setContent(QIODevice * dev, QString * errorMsg, int * errorLine, int * errorColumn) Line 6815 C++
test.exe!main(int argc, char * * argv) Line 17 + 0x19 bytes C++
test.exe!__tmainCRTStartup() Line 278 + 0x19 bytes C
test.exe!mainCRTStartup() Line 189 C
(test.exe is main.cpp)...
There is no prebuilt binary version of Qt for Visual Studio 2010.
Did you compile Qt yourself with your VS 2010 or did you use the binary from the download page (which is for VS 2008)?
Thank you for the replay.
I build it myself, the only thing that I changed was the runtime-library flag from /MDd to /MTd so my client (to be) will not need to install the redistribution, but I used the configuration provided with the source for vs2010...
also, there is no .NET at all here, and, other things, like qtsqlite and gui that I use work perfectly.
Qt and the client code must be compiled and linked with the same linker flags. Do not mix them, otherwise you might end up using two different C/C++ runtimes, which leads to memory corruption when new is called in one implementation and delete in the other.
well, they are, all /MTd and /MT (for release)
Hm, strange. I've no clue what's going wrong there. Maybe someone else will jump in - I don't have VS2010 at hand to do a check myself.
I hope so, I will try creating a static library set, just to check, worst case, the XML parsing DLL I'm working on will be created using static libraries.
anyone... HELP! hahaha
Are you sure, your Qt libs were build with /MTd and your binary also for debug and all with /MT for release?
It looks (from the defect behavior) very like these do not fit together...
How did you change the flags for Qt? Did you use dependency viewer to verify, Qt dies not use the redistributables?
I will build again and run all the nmake output to a file...
according to the build log (all 5Meg of it) there is no indication of any use of -MDd or -MD, just MT.
I am not that strong in c/c++ but,
according to the callstack we can see that the heap corruption is due to a call of a distructor of the passed &file, or one of it's components. so, we can say that the code itself cannot work with such parameters as -M, because of such call, right?
I thopught a bit about this, /MT means link against a static library, that means you add it to all binaries, you create. If you link a dll with /MT, the code is added to that dll. Then you link your executable againtst that and it is also added there. Then you have two different heaps, which leads to that crash. If you use /MT, you MUST use Qt as static library or use /MD (and the vc redistributables).
thank you Gerolf, after sleeping on it, I came also to the same conclusion.
In order for QT to be used in such a way the code must be created with 'awareness' of two (or more) different heap spaces, so, I will be linking QT statically for the xml parser..
and, the more I think about it, the more it makes sense also.
so, thank you all for the help
I rhink, you have to link Qt complete statically, or use /MD. The Qt libraries are not memory neutral (which means, memory allocate din one library may be freed in another one).