#ifndef MAINLOGIN_H
#define MAINLOGIN_H
#include <QWidget>
#include <QDialog>
#include "mainwin.h"
namespace Ui {
class mainlogin;
{
Q_OBJECT
public:
explicit mainlogin
(QWidget *parent
= 0);
~mainlogin();
{
if (mainlogin->objectName().isEmpty())
mainlogin
->setObjectName
(QString::fromUtf8("mainlogin"));
mainlogin->resize(237, 117);
horizontalLayout_4
->setObjectName
(QString::fromUtf8("horizontalLayout_4"));
horizontalLayout_4->addItem(horizontalSpacer_3);
verticalLayout_3
->setObjectName
(QString::fromUtf8("verticalLayout_3"));
verticalLayout_3->addItem(verticalSpacer);
verticalLayout_2
->setObjectName
(QString::fromUtf8("verticalLayout_2"));
verticalLayout
->setObjectName
(QString::fromUtf8("verticalLayout"));
horizontalLayout
->setObjectName
(QString::fromUtf8("horizontalLayout"));
label
= new QLabel(mainlogin
);
label
->setObjectName
(QString::fromUtf8("label"));
horizontalLayout->addWidget(label);
leUsername
->setObjectName
(QString::fromUtf8("leUsername"));
horizontalLayout->addWidget(leUsername);
verticalLayout->addLayout(horizontalLayout);
horizontalLayout_2
->setObjectName
(QString::fromUtf8("horizontalLayout_2"));
label_2
= new QLabel(mainlogin
);
label_2
->setObjectName
(QString::fromUtf8("label_2"));
horizontalLayout_2->addWidget(label_2);
lePassword
->setObjectName
(QString::fromUtf8("lePassword"));
horizontalLayout_2->addWidget(lePassword);
verticalLayout->addLayout(horizontalLayout_2);
verticalLayout_2->addLayout(verticalLayout);
horizontalLayout_3
->setObjectName
(QString::fromUtf8("horizontalLayout_3"));
horizontalLayout_3->addItem(horizontalSpacer_2);
bLogin
->setObjectName
(QString::fromUtf8("bLogin"));
horizontalLayout_3->addWidget(bLogin);
horizontalLayout_3->addItem(horizontalSpacer);
verticalLayout_2->addLayout(horizontalLayout_3);
verticalLayout_3->addLayout(verticalLayout_2);
verticalLayout_3->addItem(verticalSpacer_2);
horizontalLayout_4->addLayout(verticalLayout_3);
horizontalLayout_4->addItem(horizontalSpacer_4);
retranslateUi(mainlogin);
} // setupUi
void retranslateUi
(QDialog *mainlogin
) {
} // retranslateUi
void login()
{
QFile loginsFile
("/logins.txt");
if(loginsFile.size() == 0 || loginsFile.exists() == false)
{
error.setText("There are no logins stored. Please reinstall the program.");
error.exec();
return;
}
QString enteredUsername
= ui
->leUsername
->text
();
QString enteredPassword
= ui
->lePassword
->text
();
QString loadedLogins
= loginsStream.
readAll();
int usernameCorrect = 0;
QString filedUsername
= loadedLogins.
section("|",
1,
1);
QString filedPassword
= loadedLogins.
section("|",
2,
2);
debug.setText(enteredUsername);
debug.exec();
debug.setText(enteredPassword);
debug.exec();
debug.setText(loadedLogins);
debug.exec();
debug.setText(filedUsername);
debug.exec();
debug.setText(filedPassword);
debug.exec();
if(enteredUsername != filedUsername)
{
error.setText("Username not found!");
error.exec();
usernameCorrect = 0;
}
else
{
if(enteredPassword == filedPassword)
{
mainwin *a = new mainwin;
a->show();
}
}
} // login()
private:
Ui::mainlogin *ui;
}; // Class mainlogin
QT_END_NAMESPACE
#endif // MAINLOGIN_H
#ifndef MAINLOGIN_H
#define MAINLOGIN_H
#include <QWidget>
#include <QDialog>
#include "mainwin.h"
namespace Ui {
class mainlogin;
class mainlogin : public QDialog
{
Q_OBJECT
public:
explicit mainlogin(QWidget *parent = 0);
~mainlogin();
QHBoxLayout *horizontalLayout_4;
QSpacerItem *horizontalSpacer_3;
QVBoxLayout *verticalLayout_3;
QSpacerItem *verticalSpacer;
QVBoxLayout *verticalLayout_2;
QVBoxLayout *verticalLayout;
QHBoxLayout *horizontalLayout;
QLabel *label;
QLineEdit *leUsername;
QHBoxLayout *horizontalLayout_2;
QLabel *label_2;
QLineEdit *lePassword;
QHBoxLayout *horizontalLayout_3;
QSpacerItem *horizontalSpacer_2;
QPushButton *bLogin;
QSpacerItem *horizontalSpacer;
QSpacerItem *verticalSpacer_2;
QSpacerItem *horizontalSpacer_4;
void setupUi(QDialog *mainlogin)
{
if (mainlogin->objectName().isEmpty())
mainlogin->setObjectName(QString::fromUtf8("mainlogin"));
mainlogin->resize(237, 117);
horizontalLayout_4 = new QHBoxLayout(mainlogin);
horizontalLayout_4->setObjectName(QString::fromUtf8("horizontalLayout_4"));
horizontalSpacer_3 = new QSpacerItem(14, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
horizontalLayout_4->addItem(horizontalSpacer_3);
verticalLayout_3 = new QVBoxLayout();
verticalLayout_3->setObjectName(QString::fromUtf8("verticalLayout_3"));
verticalSpacer = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding);
verticalLayout_3->addItem(verticalSpacer);
verticalLayout_2 = new QVBoxLayout();
verticalLayout_2->setObjectName(QString::fromUtf8("verticalLayout_2"));
verticalLayout = new QVBoxLayout();
verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
horizontalLayout = new QHBoxLayout();
horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout"));
label = new QLabel(mainlogin);
label->setObjectName(QString::fromUtf8("label"));
horizontalLayout->addWidget(label);
leUsername = new QLineEdit(mainlogin);
leUsername->setObjectName(QString::fromUtf8("leUsername"));
horizontalLayout->addWidget(leUsername);
verticalLayout->addLayout(horizontalLayout);
horizontalLayout_2 = new QHBoxLayout();
horizontalLayout_2->setObjectName(QString::fromUtf8("horizontalLayout_2"));
label_2 = new QLabel(mainlogin);
label_2->setObjectName(QString::fromUtf8("label_2"));
horizontalLayout_2->addWidget(label_2);
lePassword = new QLineEdit(mainlogin);
lePassword->setObjectName(QString::fromUtf8("lePassword"));
horizontalLayout_2->addWidget(lePassword);
verticalLayout->addLayout(horizontalLayout_2);
verticalLayout_2->addLayout(verticalLayout);
horizontalLayout_3 = new QHBoxLayout();
horizontalLayout_3->setObjectName(QString::fromUtf8("horizontalLayout_3"));
horizontalSpacer_2 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
horizontalLayout_3->addItem(horizontalSpacer_2);
bLogin = new QPushButton(mainlogin);
bLogin->setObjectName(QString::fromUtf8("bLogin"));
horizontalLayout_3->addWidget(bLogin);
horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
horizontalLayout_3->addItem(horizontalSpacer);
verticalLayout_2->addLayout(horizontalLayout_3);
verticalLayout_3->addLayout(verticalLayout_2);
verticalSpacer_2 = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding);
verticalLayout_3->addItem(verticalSpacer_2);
horizontalLayout_4->addLayout(verticalLayout_3);
horizontalSpacer_4 = new QSpacerItem(14, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
horizontalLayout_4->addItem(horizontalSpacer_4);
retranslateUi(mainlogin);
QMetaObject::connectSlotsByName(mainlogin);
} // setupUi
void retranslateUi(QDialog *mainlogin)
{
mainlogin->setWindowTitle(QApplication::translate("mainlogin", "Dialog", 0, QApplication::UnicodeUTF8));
label->setText(QApplication::translate("mainlogin", "Username:", 0, QApplication::UnicodeUTF8));
label_2->setText(QApplication::translate("mainlogin", "Password:", 0, QApplication::UnicodeUTF8));
bLogin->setText(QApplication::translate("mainlogin", "Login", 0, QApplication::UnicodeUTF8));
} // retranslateUi
void login()
{
QFile loginsFile("/logins.txt");
if(loginsFile.size() == 0 || loginsFile.exists() == false)
{
QMessageBox error;
error.setText("There are no logins stored. Please reinstall the program.");
error.exec();
return;
}
QTextStream loginsStream(&loginsFile);
QString enteredUsername = ui->leUsername->text();
QString enteredPassword = ui->lePassword->text();
QString loadedLogins = loginsStream.readAll();
int usernameCorrect = 0;
QString filedUsername = loadedLogins.section("|", 1, 1);
QString filedPassword = loadedLogins.section("|", 2, 2);
QMessageBox debug;
debug.setText(enteredUsername);
debug.exec();
debug.setText(enteredPassword);
debug.exec();
debug.setText(loadedLogins);
debug.exec();
debug.setText(filedUsername);
debug.exec();
debug.setText(filedPassword);
debug.exec();
if(enteredUsername != filedUsername)
{
QMessageBox error;
error.setText("Username not found!");
error.exec();
usernameCorrect = 0;
}
else
{
if(enteredPassword == filedPassword)
{
mainwin *a = new mainwin;
a->show();
}
}
} // login()
private:
Ui::mainlogin *ui;
}; // Class mainlogin
QT_END_NAMESPACE
#endif // MAINLOGIN_H
To copy to clipboard, switch view to plain text mode
#ifndef MAINWIN_H
#define MAINWIN_H
#include <QWidget>
#include <QtGui>
{
Q_OBJECT
public:
{
setAttribute(Qt::WA_DeleteOnClose); // make sure memory is cleaned up
// Temporary
layout
->addWidget
( new QLabel("Label 1",
this) );
layout
->addWidget
( new QLabel("Label 2",
this) );
setLayout(layout);
}
};
#endif // MAINWIN_H
#ifndef MAINWIN_H
#define MAINWIN_H
#include <QWidget>
#include <QtGui>
class mainwin : public QWidget
{
Q_OBJECT
public:
mainwin(QWidget *p = 0): QWidget(p)
{
setAttribute(Qt::WA_DeleteOnClose); // make sure memory is cleaned up
// Temporary
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget( new QLabel("Label 1", this) );
layout->addWidget( new QLabel("Label 2", this) );
setLayout(layout);
}
};
#endif // MAINWIN_H
To copy to clipboard, switch view to plain text mode
Bookmarks