Yesterday I installed the latest version of the Qt SDK on my home machine (selecting only the desktop version for MinGW in the installation). Then I opened Qt Creator, selected one of the bundled example projects, built it and...
And then I got this error:
Starting D:\QtSDK\...\debug\mandelbrot.exe...
D:\QtSDK\...\debug\mandelbrot.exe exited with code -1073741511
Well, -1073741511 is just an obscene way of saying 0xC0000139, which on Windows means that some function wasn't found in a DLL. So this is Windows DLL hell (who would've thought...).
Naturally, I first suspected that Qt Creator is the culprit here. This is because when I went to directory this executable was created in and copied the relevant DLLs into it, it worked. So I started digging around the project settings in Qt Creator, but it appeared that it set up the PATH correctly to point to the installed Qt and MinGW runtime DLLs. Furthermore, it was properly appending to the beginning of PATH, so other versions of Qt potentially installed elsewhere couldn't affect it. Or could they?
The DLL search order on Windows, whichever way it is configured, always looks in the system and windows directories before it looks at the dirs on PATH. Indeed, when I went to c:\WINDOWS\system32, I was surprised (and delighted) to find a few stray Qt DLLs in there. Deleting them solved the problem!
The morale of the story: always think about the "DLL search order" when debugging problems like this. Dependency walker can help greatly here too. If your executable finds a DLL somewhere you wouldn't expect it to, depends will tell you about it.
P.S. How did the debug DLLs of Qt get into my system32? Either some application put them there during installation (a bad, bad thing to do), or I put them there for some obscure testing purpose a while ago and forgot all about them. Therefore, another morale of the story: never, EVER, put stuff in system32. Just distribute your DLLs in the same directory with the executable. Modern hard-drives are large enough to make the storage savings of DLL sharing negligible.