我在免费视频课上抄的计算器代码,自己改动之后出现的问题。用debug试出来只要运行到这里就报错:
我有试过将这里的private内容改成public
但是改完在关闭的时候还是会出现引用内存不能为read
不过改成public如果程序打开了没有使用的话,能正常关闭
下面是相关的一些部分,请问这是什么情况?应该怎么解决?
如果给的信息不够,我会尽快补充,谢谢
另外标签写c++不知道对不对,只是找不到单独的qt选择,而qt说是c++的类库
void Dialog::on_btn_plus_clicked()
{
double tmp = this->ui->lcdNumber->value();
this->cal->setNum1(tmp);
this->Num = "";
QString ex = this->ui->btn_plus->text();
this->cal->setFlag(ex);
}
void Dialog::on_btn_equal_clicked()
{
double tmp = this->ui->lcdNumber->value();
this->cal->setNum2(tmp);
QString end = this->cal->doCal();
this->ui->lcdNumber->display(end);
this->cal->setNum1(tmp);
this->Num = "";
}
QString calculate::doCal()
{
float rst = 0;
QString flg = this->flag;
if(flag == "+"){
rst = this->num1 + this->num2;
}else if(flag == "-"){
rst = this->num1 - this->num2;
}else if(flag == "*"){
rst = this->num1 * this->num2;
}else if(flag == "/"){
if(this->num2 == 0){
return "ERROR";
}
rst = this->num1 / this->num2;
}
}