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

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

 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); // 关闭的时候delete
    dialog->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)指针也可以解决

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

米杰的声音

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值