Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Program crashes (SIGSEGV Segmentation Fault)
Forum Update on Monday, May 27th 2025

Program crashes (SIGSEGV Segmentation Fault)

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 1.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hadifyassin
    wrote on last edited by A Former User
    #1

    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
     }
    
    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      Use the debugger.
      Single step through the code
      and find the line that makes your app crash.

      1 Reply Last reply
      1
      • H Offline
        H Offline
        hadifyassin
        wrote on last edited by
        #3

        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!

        mrjjM 1 Reply Last reply
        2
        • H hadifyassin

          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!

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @hadifyassin
          Well thats happens to most of us from time to time :)
          Where there is action, there will be Whoops ;)

          1 Reply Last reply
          1

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved