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. Form Login with QDialog
Forum Updated to NodeBB v4.3 + New Features

Form Login with QDialog

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 1.1k Views 1 Watching
  • 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.
  • C Offline
    C Offline
    Caio.Sousa
    wrote on last edited by Caio.Sousa
    #1

    Hi Guys,

    I'm trying to create a login form using QDialog, but when I click Login, I can not give .exec () on mainWindow which would be the panel for my program.

    I wanted to do something so that I would type the login and open the panel and delete the form login.

    Does anyone have any ideas?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Please show the code you are using.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • C Offline
        C Offline
        Caio.Sousa
        wrote on last edited by
        #3

        MAIN.CPP

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

        int main(int argc, char *argv[])
        {
        QApplication a(argc, argv);
        logar w;
        w.show();

        return a.exec();
        

        }

        LOGAR.CPP

        #include "logar.h"
        #include "ui_logar.h"
        #include <QMessageBox>
        #include "menuinicial.h"
        #include <fstream>
        #include <cadastrar.h>

        logar::logar(QWidget *parent) :
        QDialog(parent),
        ui(new Ui::logar)
        {
        ui->setupUi(this);
        connect(ui->btnEntrar,SIGNAL(on_btnEntrar_clicked()),this,SLOT(validacaoLogin()));
        }

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

        bool logar::validacaoLogin(){
        QString usuario = ui->txtNome->text();
        QString senha = ui->txtSenha->text();

        using namespace std;
        ofstream fout("C:\\Users\\Caio\\Documents\\login.txt", ios::app);
        
        fout <<usuario.toStdString()<<endl;
        fout <<senha.toStdString()<<endl;
        
        if(usuario == "Caio Sousa" && senha =="12345"){
            return true;
        
        }else{
            return false;
        }
        

        }

        void logar::validacaoFuncionarios(){
        using namespace std;
        ifstream fin("C:\Users\Caio\Documents\login.txt");
        char temp;
        QString buffer;
        while (fin.get(temp)) {
        buffer.push_back(QChar(temp));

        }
        

        }

        void logar::on_btnEntrar_clicked()

        {

         validacaoFuncionarios();
        
        if(validacaoLogin()==true){
        
            //Here should show the mainWindow(Menu)
        
        
        
        }else{
            QMessageBox::warning(this,"Login","Usuario ou senha incorretos");
        }
        

        }

        void logar::on_btnCadastrar_clicked()
        {
        cadastrar cadastra;
        cadastra.exec();
        }

        LOGAR.H

        #ifndef LOGAR_H
        #define LOGAR_H

        #include <QDialog>
        #include <QtCore>

        namespace Ui {
        class logar;
        }

        class logar : public QDialog
        {
        Q_OBJECT

        public:
        explicit logar(QWidget *parent = nullptr);
        ~logar();

        private slots:
        void on_btnEntrar_clicked();
        bool validacaoLogin();
        void validacaoFuncionarios();

        void on_btnCadastrar_clicked();
        

        private:
        Ui::logar *ui;
        QFile *file;
        QTextStream stream;
        };

        #endif // LOGAR_H

        MENUINICIAL.H

        #ifndef MENUINICIAL_H
        #define MENUINICIAL_H

        #include <QMainWindow>

        namespace Ui {
        class MenuInicial;
        }

        class MenuInicial : public QMainWindow
        {
        Q_OBJECT

        public:
        explicit MenuInicial(QWidget *parent = nullptr);
        ~MenuInicial();

        private slots:
        void on_btnBuscar_clicked();

        private:
        Ui::MenuInicial *ui;
        };

        #endif // MENUINICIAL_H

        MENUINICIAL.CPP

        #include "menuinicial.h"
        #include "ui_menuinicial.h"
        #include "cadastroquarto.h"

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

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

        void MenuInicial::on_btnBuscar_clicked()
        {
        cadastroQuarto quarto;
        quarto.exec();
        }

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          You're doing way too much stuff in your login dialog.

          You should only be doing the validation there, and in the main function show the the MainWindow if the validation passes. You can use QDialog's exec function to run your dialog before continuing.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          2
          • C Offline
            C Offline
            Caio.Sousa
            wrote on last edited by
            #5

            I'm still learning using QT Creator, but the tutorial I'm seeing is not teaching you how to use the main class the right way

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              What main class ? If you mean the main function, you won't find tutorials for each and every possible way to write an application.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0

              • Login

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