WUT_Computer_Science/EGUI/lab1/mainwindow.cpp

55 lines
1.6 KiB
C++
Raw Normal View History

#include "mainwindow.h" // Notepad class header file that was generated by the wizard
#include "ui_mainwindow.h" // UI header file that was generated by the uic tool
#include <QFileDialog>
#include <QMessageBox>
#include <iostream>
#include <QJsonObject>
#include <QJsonDocument>
#include <QTextStream>
2022-03-26 12:43:58 +01:00
MainWindow::MainWindow(QWidget *parent) // class definition, constructor
: QMainWindow(parent) // calls qmainwindow parent constructor we have,
// base class for the MainWindow class:
, ui(new Ui::MainWindow) // create ui class and assign to ui member
// creates the UI class instance and assigns it to the ui member:
2022-03-26 12:43:58 +01:00
{
ui->setupUi(this); // setup user interface
2022-03-26 12:43:58 +01:00
}
MainWindow::~MainWindow()
{
delete ui; // in the destructor, we delete the ui
}
void MainWindow::saveJsonFile(QJsonObject &json) const
{
QFile jsonFile(QStringLiteral("save.json"));
QJsonDocument document;
document.setObject( json );
QByteArray bytes = document.toJson( QJsonDocument::Indented );
jsonFile.open( QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate );
QTextStream iStream( &jsonFile );
// iStream.setCodec( "utf-8" );
iStream << bytes;
jsonFile.close();
}
void MainWindow::saveRegisteredUser(QJsonObject &json) const
{
QString mail = ui->inputMail->text();
QString password = ui->inputPassword->text();
qDebug() << mail << " " << password;
json["mail"] = mail;
json["password"]=password;
saveJsonFile(json);
}
void MainWindow::on_pushButton_clicked()
{
QJsonObject saveFile;
saveRegisteredUser(saveFile);
2022-03-26 12:43:58 +01:00
}