Problem login window



  • Hi,
    on my Main Window I entered an icon for login. 0_1530238704110_Cattura.JPG
    I would like the icon to go off after you have logged in or or I would like a window to come out: "Access already done" and an option to disconnect.
    can you help me please?
    (Sorry my english)


  • Moderators



  • @jsulm said in Problem login window:

    @fra_mecc http://doc.qt.io/qt-5/qwidget.html#enabled-prop

    Thank you so much but I still do not understand how I can tell Qt that the icono must go off if the condition (username and password == "test")


  • Moderators

    @fra_mecc

    ui->button->setEnabled(false);
    

    Where exactly is the problem?



  • @jsulm Sorry, I expressed myself badly. I've already done this. I do not understand how to make Qt understand the login condition



  • @jsulm I should define a function (?) so if "Username and password == test" then my icon goes off. But I do not know how to define the function



  • @fra_mecc hi,
    Whitch kind of application is this? Could you show your code exemple ?

    one solution could be to having states on your client, ( connected, disconnected )
    Create a boolean bool connected=false;
    then in your connection funtion, if (username=="test" && pass=="test") connected=true

    after this you can use 'connected' as condition

    //qml exemple
    Image{
    source : connected ? "img/disconect.png" : "img/connect.png"
    }



  • @LeLev I did not understand much ..I show you the code of dialog file:

    #include "accedi.h"
    #include "ui_accedi.h"
    #include <QMessageBox>
    #include <QLineEdit>
    
    Accedi::Accedi(QWidget *parent) :
        QDialog(parent),
        ui(new Ui::Accedi)
    {
        ui->setupUi(this);
        setWindowTitle("Accedi");
        setWindowIcon(QIcon("accedi.png"));
    }
    
    Accedi::~Accedi()
    {
        delete ui;
    }
    
    void Accedi::on_buttonBox_accepted()
    {
    
    }
    
    void Accedi::on_pushButton_2_clicked()
    {
        hide();
    }
    
    void Accedi::on_pushButton_clicked()
    {
        QString username = ui->lineEdit_username->text();
        QString password = ui->lineEdit_password->text();
    
        if(username == "test" && password == "test") {
            ui->status->setText("Accesso effettuato.");
            QMessageBox::information(this, "Accesso effettuato",
                                           "Bentornato! \nOra potrai usare il programma registrando automaticamente i risultati sul tuo account.");
            hide();
            ui->status->clear();
            ui->status->setText("Connessione...");
            ui->lineEdit_username->clear();
            ui->lineEdit_password->clear();
    
    
        }
        else {
            ui->status->setText("Accesso Negato! Username o password errati");
            //ui->status->clear();
            ui->lineEdit_username->clear();
            ui->lineEdit_password->clear();
    
            //QMessageBox::warning(this, "Accesso negato", "Username e password sono errati");
        }
    
    
    
    }
    
    ```and this is the part of code of Main Windows (where there is the icon):
    

    }

    void MainWindow::on_actionLogin_2_triggered()
    {
    login->show();
    }



  • @fra_mecc

    if(username == "test" && password == "test") {
            ui->status->setText("Accesso effettuato.");
    
    // can't you change your image here ?  ui->yourIcon->setEnabled(false);
    
            QMessageBox::information(this, "Accesso effettuato",
                                           "Bentornato! \nOra potrai usare il programma registrando automaticamente i risultati sul tuo account.");
            hide();
            ui->status->clear();
            ui->status->setText("Connessione...");
            ui->lineEdit_username->clear();
            ui->lineEdit_password->clear();
    
    
        }
        else {
            ui->status->setText("Accesso Negato! Username o password errati");
            //ui->status->clear();
            ui->lineEdit_username->clear();
            ui->lineEdit_password->clear();
    
            //QMessageBox::warning(this, "Accesso negato", "Username e password sono errati");
        }
    


  • @LeLev ui-> yourIcon->setEnabled(false); it's a piece of code that belongs to the main window while the if loop belongs to a "login" file.
    It does not let me insert the Main Windows code in the other file



  • @fra_mecc

    if loop belongs to a "login" file.
    It does not let me insert the Main Windows code in the other file

    You could emit the accept or reject signal of dialog and capture them of mainwindow:
    NOTE: when accept or reject signals are emitted, your dialog is forced to close.

    Login Dialog cpp

    if(username == "test" && password == "test") {
            ui->status->setText("Accesso effettuato.");
    
            QMessageBox::information(this, "Accesso effettuato",
                                           "Bentornato! \nOra potrai usare il programma registrando automaticamente i risultati sul tuo account.");
            ui->status->clear();
            ui->status->setText("Connessione...");
            ui->lineEdit_username->clear();
            ui->lineEdit_password->clear();
    
            accept(); // emit accept signal
        }
        else {
            ui->status->setText("Accesso Negato! Username o password errati");
            ui->lineEdit_username->clear();
            ui->lineEdit_password->clear();
    
            //QMessageBox::warning(this, "Accesso negato", "Username e password sono errati");
        }
    

    main window :

    void MainWindow::on_actionLogin_2_triggered () 
    { 
      int returnCode = login->exec();
    
      if(returnCode == QDialog::Accepted)  // returns by accept signal
         ui->yourIcon->setEnabled(false);
      else if(dialogCode == QDialog::Rejected)
         ui->yourIcon->setEnabled(true);
    }
    

    or you can connect thefinished (int)signal of login dialog to a mainwindow slot or lambda function and do the same action.



  • This post is deleted!


  • @KillerSmath Resolved! Thanks so much! I do not know how to thank you..



  • @fra_mecc up vote him :p


  • Moderators

    @fra_mecc Keep in mind that it is very easy to find the user name and password in your executable. So, if an user with a bit of knowledge gets your app he/she will extract the user name and password from the executable file.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.