当前位置: 代码迷 >> 综合 >> 【QT】野指针报错The inferior stopped because it received a signal from the Operating System.
  详细解决方案

【QT】野指针报错The inferior stopped because it received a signal from the Operating System.

热度:83   发布时间:2023-12-16 20:16:36.0

 运行的时候会崩溃,并提示如下错误:

 Signal received

 The inferior stopped because it received a signal from the Operating System.

 Signal name : SIGSEGV

 Signal meaning : Segmentation fault

这个错误说明程序中有野指针,断点以下很容易找出错误。
 

void PLCTempControl::on_actionHelp_triggered()
{QDialog *dialog = new QDialog();Ui::Dialog ui;ui.setupUi(dialog);dialog->setAttribute(Qt::WA_DeleteOnClose); // 关闭的时候deletedialog->setWindowTitle("通信协议");ui.tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch );// 自适应列宽ui.tableWidget->horizontalHeader()->setSectionResizeMode(2,QHeaderView::ResizeToContents );// 适应单元格内容ui.tableWidget->horizontalHeader()->setSectionResizeMode(3,QHeaderView::ResizeToContents );// 适应单元格内容ui.tableWidget->horizontalHeader()->setSectionResizeMode(4,QHeaderView::ResizeToContents );// 适应单元格内容dialog->show();
}

出错在指针

ui.tableWidget->horizontalHeader();

指针非空,但是调动 “->函数” 时会报错;

因为指针指向的对象是临时变量,临时变量会在其函数结束时即被释放。
故 m_pCurSldRels 变为了一个野指针,在其他调动 “->函数” 时会报错。

改正:不能用指针,就直接定义为对象

在使用信号--槽之前示例化(new)指针也可以解决

  相关解决方案