0

I created a simple login program in C++ GUI but for some reason the condition that makes the if statement true is always true no matter what. I've looked at a bunch of times now and I really don't know whats ccausing this, any input would be appreciated.

#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}



void MainWindow::on_pushButton_clicked()
{
    QString username, password;
    username=ui->lineEdit->text();
    password=ui->lineEdit_2->text();

    truee=0;

    if (username=="Brandan")
    {
        truee=1;
    }

    if (password=="ABC123")
    {
        truee=truee+1;
    }

    if(truee=2)
    {
        ui->label->setText("Login succesful");
    }
    else
    {
        ui->label->setText("Failed");
    }
}
Maxim Makhun
  • 2,197
  • 1
  • 22
  • 26
user3183586
  • 167
  • 1
  • 5
  • 15

1 Answers1

4

if(truee=2) has to be changed to if(truee==2)

timrau
  • 22,578
  • 4
  • 51
  • 64
Asanga Dewaguru
  • 1,058
  • 2
  • 16
  • 31