QT throws exception reason

The reason for the abnormal termination of the Qt program:

1. Before using the pointer, it is necessary to judge whether the pointer is null. If it is NULL but directly uses the pointer, it will terminate abnormally.
For example, in QTableView: QStandardItemModel *model = new QStandardItemModel;
model->item(0,1)->text()
cell has not been edited, directly use model->item(0,1)->text(), the program will terminate abnormally.

2. After adding the delete code to release the memory in the destructor, the Qt application will be closed, and the program will terminate abnormally. If you remove the delete code in the destructor, there will be no problem.
I add an additional Qt designer interface class inherited from QTableView in the project, and in ui_widget.h, that is, the source code of the widget.ui interface, change QTableView to the class name of my added class. In the cpp file of the newly created class, comment out ui(new Ui::CTblView); ui->setupUi(this); two lines, but do not comment out delete ui; the reason is the same as the first point, ui is
defined If you use it, you will delete it directly, which will cause the program to terminate abnormally. It is normal to comment out this line too.

3. Reference the pointer object without instantiation
For example: Dialog *d; d = new Dialog; d->show(); If you forget the instantiation of the second line, it will also cause the Qt program to terminate abnormally.


Reposted from Baidu: https://zhidao.baidu.com/question/433068969.html

Guess you like

Origin blog.csdn.net/qq_42788340/article/details/113636777