C++ Program Unexpectedly Finished
2020-10-08 20:21:04 Author: jcjc-dev.com(查看原文) 阅读量:128 收藏

03 Mar 2013

Error: The program has unexpectedly finished

This is a common error while working with Qt (and C++ in general). You will write some code, compile it without errors or warnings and when you run the application it will crash and throw a “The program has unexpectedly finished.” in the Application Output.

The most common cause of this is using an object you have declared a pointer for but have not allocated.

This piece of code will make the application crash:

QPushButton *myButton;
myGridLayout->addWidget (myButton, 0, 0, Qt::AlignLeft);

But this one won’t:

QPushButton *myButton;
myButton = new QPushButton ("button's text");
myGridLayout->addWidget (myButton, 0, 0, Qt::AlignLeft);

The first example is obviously wrong, but it’s easy to forget the memory allocation when the code starts getting longer.


文章来源: https://jcjc-dev.com/2013/03/03/c++-program-unexpectedly-finished/
如有侵权请联系:admin#unsafe.sh