Qt World Summit: Register Today!

Qt 4.8.1 app crashes on exit, Qt 4.7.4 runs OK

  • I have been developing Qt applications for a few years using Qt 4.7.4 with MSVC 2005. Things have been going smoothly. Recently I needed to start transferring my code to Qt 4.8.1 using MSVC 2010. Now a program that used to run OK gives me an error message saying that it has crashed when I close it (clicking the RH 'X' button). I can reproduce the problem with a program that does nothing but setupUi(). That is:

    int main(int argc, char *argv[])
    QApplication app(argc, argv);
    MainWindow mainWin;

    return app.exec();


    MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)

    About 4 seconds after I click the close button, I get:

    "The program has unexpectedly finished.
    D:\trophocell-abm\tropho_GUI-build-Qt_4_8_1\release\tropho_GUI.exe crashed"

    The 4 second delay is interesting - what is it doing?
    I presume there is something in my .ui file that is creating a problem. How can this happen? The UI is created as I would expect, and the error occurs on exit.

    I am building and running in Qt Creator.

    Any ideas? Is it likely to be caused by a change in Qt, or a change in MSVC?


    [edit: added missing coding tags @ SGaist]

  • Lifetime Qt Champion


    Did you try to run it through the debugger ?

  • I did just install MS SDK to get access to CDB. It is not a trivial matter for me to build a debug version of this app, because it links to the VTK libraries, which I will have to build debug versions of. To clarify, in the simple test that fails much more code is built than I showed, but the error can be demonstrated when MainWindow returns without doing anything except setupUi. I did run the debugger anyway, and it told me:

    HEAP[tropho_GUI.exe]: Invalid address specified to RtlFreeHeap( 00290000, 050913E0 )

    On a guess I removed a qwtPlot widget that I have been using. This prevents the crash with the simple example. But when I run the complete program (with without that qwtPlot) it crashes on exit again (after executing correctly), with the same heap error. I surmise that this is related to other uses I make of qwtPlot widgets that are created dynamically. It is not clear to me at this stage if the problem is an incompatibility of the qwt library (5.2.1, built with MSVC 2005) with MSVC 2010, or if I am just doing something wrong. The fact that it all works with MSVC 2005 suggests an incompatibility. Perhaps I need to rebuild the qwt library with MSVC 2010. Perhaps you can suggest a way I can remove the qwtPlot widgets myself (in closeEvent()) on exit instead of leaving it to Qt to do it automatically.


  • Lifetime Qt Champion

    You can't mix dlls from several versions of MSVC. The rule is: everything must be compiled with the same version of Visual Studio. Their compiler are not compatible one with the other.

  • I think that's true for static libraries but not necessarily for DLLs. I am linking to another DLL built with MSVC 2005, and I can even replace that with a DLL built with MinGW (in that case I have to take special measures to generate the .lib). In any case, I have found that my problem is solved by deleting the QwtPlot objects in closeEvent(). It's all working now.

Log in to reply