Home > database >  How to create QT Login Page bedore Mainwindow?
How to create QT Login Page bedore Mainwindow?

Time:04-26

My Qt windows application is ready, but when the application opens, I want the login dialog to be opened, how can I do this? I'm new to Qt and C . It would be great if it was descriptive.

CodePudding user response:

You have many ways to achieve that... QDialog is a nice way. Here is a short sample using QInputDialog.

One solution could be to add this code in your main.cpp file, and to load the mainwindow only if the credentials are ok.

#include "gmainwindow.h"
#include <QApplication>

#include <QInputDialog>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
            
    GMainWindow w;
            
    QString login = QInputDialog::getText(NULL, "Login","Name ?",QLineEdit::Normal);
            
    if (login == "USER")
    {            
        w.show();
    }
    else
    {           
        //display an error message
        return a.quit();
    }
    
    return a.exec();
}

Of course you may want to put an encrypted password and other things, but the idea will be more or less the same.

  • Related