PDA

View Full Version : create login page



smemamian
19th April 2013, 14:47
hi

i want to create a login page .
But this code does not work . :(

setPass.h


#ifndef SETPASS_H
#define SETPASS_H

#include <QDialog>

namespace Ui {
class setPass;
}

class setPass : public QDialog
{
Q_OBJECT

public:
explicit setPass(QWidget *parent = 0);
~setPass();
void setPassword(QString &pass);
void setUsername(QString &user);
bool setBool();

private slots:
void on_pushButton_clicked();

private:
Ui::setPass *ui;
QString pass , user ;
bool res1 , res2 ;

};

#endif // SETPASS_H

setPass.cpp


#include "setpass.h"
#include "ui_setpass.h"

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

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

void setPass::setPassword(QString &pass)
{

QString c_pass = "123456";
int a = c_pass.compare(pass);
if(a == 0)
res1 = true ;
}

void setPass::setUsername(QString &user)
{

QString c_user = "m";
int a = c_user.compare(user);
if( a == 0 )
res2 = true ;
}

void setPass::on_pushButton_clicked()
{
setUsername(user = ui->userName->text());
setPassword( pass = ui->passWord->text());
}

bool setPass::setBool()
{
if(res2 == true && res1 == true)
return true ;
else return false ;
}

main.cpp


#include "mainwindow.h"
#include <QApplication>
#include "dialog.h"
#include "setpass.h"

int main(int argc, char *argv[])
{
QApplication a(argc, argv);

setPass pas ;
pas.show();
if(pas.setBool())
{
MainWindow w;
pas.close();
w.show();
}
return a.exec();
}

pic:

8967

Santosh Reddy
19th April 2013, 14:58
Call pas.exec(); instead of pas.show();

smemamian
19th April 2013, 16:42
ok, but when i click on ok button, the user and pass window does not close ! Then when I close the user and pass window manually, The main window opens.

amleto
19th April 2013, 21:46
void setPass::on_pushButton_clicked()
{
setUsername(user = ui->userName->text());
setPassword( pass = ui->passWord->text());
accept(); // <<<<<<<<<<<<
}

smemamian
20th April 2013, 10:40
Does not work,when i click ok button, the user and pass window is closed !

amleto
20th April 2013, 13:01
ok, but when i click on ok button, the user and pass window does not close ! Then when I close the user and pass window manually, The main window opens.


Does not work,when i click ok button, the user and pass window is closed !

Make up your mind...

wysota
20th April 2013, 13:28
Why wouldn't it be closed?

@amleto: I think he doesn't want to close the dialog until the user explicitly requests so. Which doesn't make much sense but I think that's OP's idea...

smemamian
20th April 2013, 17:43
http://tinypic.com/player.php?v=2hzibmd&s=4

amleto
20th April 2013, 18:21
going back to this


#include "mainwindow.h"
#include <QApplication>
#include "dialog.h"
#include "setpass.h"

int main(int argc, char *argv[])
{
QApplication a(argc, argv);

setPass pas ;
pas.show();
if(pas.setBool())
{
MainWindow w;
pas.close();
w.show();
}
// what do you think has happened to 'w' here? Answer: it does not exist.
return a.exec();
}



#include "mainwindow.h"
#include <QApplication>
#include "dialog.h"
#include "setpass.h"

int main(int argc, char *argv[])
{
QApplication a(argc, argv);

setPass pas ;
pas.exec(); // exec not close
if(pas.setBool())
{
MainWindow w;
//pas.close(); // this is already closed
w.show();

return a.exec();
}

return 1;
}

smemamian
20th April 2013, 18:45
i changed :


void setPass::on_pushButton_clicked()
{
setUsername(user = ui->userName->text());
setPassword( pass = ui->passWord->text());
if(setBool())
accept();
}

Thank you all.