binary001
10th October 2015, 17:44
Hi,
After I pressed pushbutton (four times) , variable i is reach 3 (a array is out of range so) application is crashed.
I don't fix this error with checking of array size. I only want to use try .. catch in sample
//header file
QString a[3];
int i;
//cpp file
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
a[0]="Zero";
a[1]="Three";
a[2]="Two";
i=0;
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
try {
ui->label->setText(a[i++]);
}
catch(std::exception &e){
qDebug() << "error1" << endl;
}
catch (...)
{
qDebug() << "error2" << endl;
}
}
After I pressed pushbutton (four times) , variable i is reach 3 (a array is out of range so) application is crashed.
I don't fix this error with checking of array size. I only want to use try .. catch in sample
//header file
QString a[3];
int i;
//cpp file
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
a[0]="Zero";
a[1]="Three";
a[2]="Two";
i=0;
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
try {
ui->label->setText(a[i++]);
}
catch(std::exception &e){
qDebug() << "error1" << endl;
}
catch (...)
{
qDebug() << "error2" << endl;
}
}