Hi! I'm so new to qt and i don't know how to do a filestream. I am creating a login form-filestream based. So i need to create a login form which has of course username and password. First what i did was to use SQLITE as a database and it worked. But the problem is. I have to use filestream that would end up making a new .txt file where the username and passwords would be inputed. I don't know the proper codes to be used in making a filestream from qt and i don't know where in my main code i should put it. i badly need help. The codes that are written there are for sqlite base but i need to change it to a filestream type that would be based from a .txt file. Here's my code:
#include "login.h"
#include "ui_login.h"
#include <QMessageBox>
#include <QPixmap>
#include <QFont>
#include <QSplashScreen>
#include <QTimer>
ui(new Ui::Login)
{
ui->setupUi(this);
QPixmap pix
("C:/Users/Patch/Documents/COE113PROJ/Login/LOGINFORM/images/background.jpg");
ui->background->setPixmap(pix);
mydb.setDatabaseName("C:/Users/Patch/Documents/COE113PROJ/Login/LOGINFORM/sqlite/users.db");
if(!mydb.open())
ui->status->setText("Failed to open the database");
else
ui->status->setText("Connected Succesfuly");
}
Login::~Login()
{
delete ui;
}
void Login::on_pushButton_login_clicked()
{
name=ui->lineEdit_Username->text();
password=ui->lineEdit_Password->text();
if(!mydb.isOpen()){
qDebug()<<"Failed to open the database";
return;
}
if(qry.
exec("select * from users.dbhalp.jpg where name='"+name
+"'and password='"+password
+"'")) {
int count=0;
while(qry.next())
{
count++;
}
if(count==1)
{
QMessageBox::information(this,
"Login",
"Username and password is correct ");
hide();
secDiag = new SecDiag(this);
secDiag->show();
}
if(count>1)
{
QMessageBox::information(this,
"Login",
"Username and password is incorrect");
}
if(count<1)
{
QMessageBox::information(this,
"Login",
"Username and password is incorrect");
}
}
}
#include "login.h"
#include "ui_login.h"
#include <QMessageBox>
#include <QPixmap>
#include <QFont>
#include <QSplashScreen>
#include <QTimer>
Login::Login(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::Login)
{
ui->setupUi(this);
QPixmap pix("C:/Users/Patch/Documents/COE113PROJ/Login/LOGINFORM/images/background.jpg");
ui->background->setPixmap(pix);
mydb = QSqlDatabase::addDatabase("QSQLITE");
mydb.setDatabaseName("C:/Users/Patch/Documents/COE113PROJ/Login/LOGINFORM/sqlite/users.db");
if(!mydb.open())
ui->status->setText("Failed to open the database");
else
ui->status->setText("Connected Succesfuly");
}
Login::~Login()
{
delete ui;
}
void Login::on_pushButton_login_clicked()
{
QString name,password;
name=ui->lineEdit_Username->text();
password=ui->lineEdit_Password->text();
if(!mydb.isOpen()){
qDebug()<<"Failed to open the database";
return;
}
QSqlQuery qry;
if(qry.exec("select * from users.db[ATTACH=CONFIG]11923[/ATTACH] where name='"+name+"'and password='"+password+"'"))
{
int count=0;
while(qry.next())
{
count++;
}
if(count==1)
{
QMessageBox::information(this,"Login","Username and password is correct ");
hide();
secDiag = new SecDiag(this);
secDiag->show();
}
if(count>1)
{
QMessageBox::information(this,"Login","Username and password is incorrect");
}
if(count<1)
{
QMessageBox::information(this,"Login","Username and password is incorrect");
}
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks