-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainwindow.cpp
87 lines (59 loc) · 1.9 KB
/
mainwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "loguser.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
//=================== DATABASE INTEGRAATION ============================================
ui->setupUi(this);
mydb=QSqlDatabase::addDatabase ("QSQLITE") ;
mydb. setDatabaseName ("C:/Users/Raghav Singla/OneDrive/Desktop/SQLITE/sqlite-tools-win-x64-3450200/myrecipe.db") ;
if(!mydb.open()){
ui->label_3->setText("Failed to connect to Database");
}
else{
ui->label_3->setText("Conneted...");
}
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
QString name , username , password;
name = ui->lineEdit->text();
username = ui->lineEdit_2->text();
password = ui->lineEdit_3->text();
if(!mydb.isOpen()){
qDebug()<<"Failed to open the databse";
return;
}
QSqlQuery qry;
QString queryStr = "INSERT INTO user (name ,username, password) VALUES ('" + name + "', '" + username + "', '" + password + "')";
if (qry.exec(queryStr)){
ui->label_3->setText("User added successfully");
this->close();
loginuser = new logUser(this);
loginuser -> show();
}
else {
qDebug() << "Error executing query: " << qry.lastError().text();
ui->label_3->setText("Failed to add user");
}
}
// ========================================Login Window Open From Here==============================================
void MainWindow::on_pushButton_2_clicked()
{
// Close the current MainWindow
this->close();
// Open the login window
logUser *loginWindow = new logUser();
loginWindow->show();
}
// =================================== Close Button =============================================================
void MainWindow::on_pushButton_3_clicked()
{
this->close();
}