When using Qt with STL it crashes with a memory access exception, how do I fix this?

If this happens, then the problem is usually either one of two things:

  • A mismatch of runtime libraries – If you have built Qt in release mode and
    your application in debug mode this means that it will be using two different
    runtime libraries. A release C runtime for Qt and a debug C runtime for your
    application. This means that there are two heaps in use and as a result if
    objects get passed from one heap to another (i.e. from Qt to the application
    and vice versa) then memory corruption will occur. You can usually catch this
    at build time, if you see a link warning about default libraries then this is
    usually indicitive of this problem. The only way to resolve it is to ensure
    that Qt and your application is built in the same mode. With Qt 4, by default
    both versions are available so you should not encounter this problem.
  • The environment variables are not set correctly – If you have more than
    one compiler installed on your machine, then it is possible that the
    environment variables (particularly INCLUDE and LIB) are not pointing to the
    right compiler. You should ensure that the environment variables match the
    compiler that you are actually using to build and run the application.

1 comment

November 10, 2010

Picture of chantivlad chantivlad

Lab Rat

I compiled every single library in my project with /MDd and I still get one of these crashes.

See http://developer.qt.nokia.com/forums/viewthread/1690

Write a comment

Sorry, you must be logged in to post a comment.