Program crashes (SIGSEGV Segmentation Fault)
-
The Program is basically a login app with a text file as its database.
The Program works fine with the admin username and password, but when I enter the login details from the text file,it crashes. when I debug it says"The inferior stopped because it received a signal from the operating system.
Signal name: SIGSEGV
Signal meaning: Segmentation fault"Somebody Please help me with this. THANK YOU in Advance.
Here is my Code(as readable as possible):#include "mainwindow.h" #include "ui_mainwindow.h" #include<QMessageBox> #include<QPixmap> #include<QFile> #include<QTextStream> #include"dialog.h" MainWindow::MainWindow(QWidget *parent) : MainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); ui->progressBar->hide(); //ui->label_pic->setMaximumWidth(167); QPixmap pix("://login.png"); int w=ui->label_pic->width(); int h=ui->label_pic->height(); ui->label_pic->setPixmap(pix.scaled(w,h,Qt::KeepAspectRatio)); } MainWindow::~MainWindow() { delete ui; } void MainWindow::on_pushButton_clicked() { QString name[100],pass[100]; int k; QFile user(".data.txt"); QString username=ui->lineEdit_username->text(),password=ui->lineEdit_password->text(); QTextStream in(&user); for(int i=0;!in.atEnd();i++) { in>>name[i]>>pass[i];//read from text } user.close(); for(int i=0;i<100;i++) { if((name[i]==username)&&(pass[i]==password))//comparing entered values { k=i; goto bo; } else if(ui->lineEdit_username->text()=="hadifyassin"&&ui->lineEdit_password->text()=="Hadif123")//admin username and password goto yo; } bo: if((username==name[k])&&(password==pass[k])){ ui->progressBar->show(); ui->statusBar->showMessage("Login Successful",5000); ui->progressBar->setValue(100); hide(); //QMessageBox::information(this,"Success","Logged In"); Dialog *secDialog; secDialog = new Dialog(this); secDialog->show();}//show second window else{ yo: if((ui->lineEdit_username->text()=="hadifyassin"&&ui->lineEdit_password->text()=="Hadif123"))//admin { ui->progressBar->show(); ui->statusBar->showMessage("Login Successful",5000); ui->progressBar->setValue(100); hide(); //QMessageBox::information(this,"Success","Logged In"); m = new menu(this); m->show();//show admin window } else { ui->statusBar->showMessage("Login unsuccessful",5000); QMessageBox::warning(this,"Failed","Username or Password Incorrect"); hide(); reg=new Register(this); reg->show();//register } } } void MainWindow::on_pushButton_2_clicked() { hide(); reg=new Register(this); reg->show();//register }
-
Hi
Use the debugger.
Single step through the code
and find the line that makes your app crash. -
I am soo sorry for asking such a silly dumb question. The problem was just that the file wasn't open. I fixed it. Thank you soo much for your help. I feel soo silly!
-
I am soo sorry for asking such a silly dumb question. The problem was just that the file wasn't open. I fixed it. Thank you soo much for your help. I feel soo silly!
@hadifyassin
Well thats happens to most of us from time to time :)
Where there is action, there will be Whoops ;)