mirror of
https://github.com/kuhyx/WUT_Computer_Science.git
synced 2026-07-04 17:03:12 +02:00
47 lines
1.0 KiB
C++
47 lines
1.0 KiB
C++
|
|
#ifndef UNIVERSAL_FUNCTIONS_CPP
|
||
|
|
#define UNIVERSAL_FUNCTIONS_CPP
|
||
|
|
#include <QJsonObject>
|
||
|
|
#include <QString>
|
||
|
|
#include <QJsonDocument>
|
||
|
|
#include <QFile>
|
||
|
|
#include <QMessageBox>
|
||
|
|
#include <QApplication>
|
||
|
|
|
||
|
|
QJsonObject readJsonFile(const QString title)
|
||
|
|
{
|
||
|
|
QFile file(title);
|
||
|
|
file.open(QIODevice::ReadWrite);
|
||
|
|
QByteArray bytes = file.readAll();
|
||
|
|
file.close();
|
||
|
|
QJsonDocument document = QJsonDocument::fromJson( bytes );
|
||
|
|
return document.object();
|
||
|
|
}
|
||
|
|
|
||
|
|
void saveJsonFile(QJsonObject &users, const QString name)
|
||
|
|
{
|
||
|
|
QFile jsonFile(name);
|
||
|
|
QJsonDocument document;
|
||
|
|
document.setObject( users );
|
||
|
|
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 outputMessageBox(const QString messageBoxText)
|
||
|
|
{
|
||
|
|
QMessageBox idEmpty;
|
||
|
|
idEmpty.setText(messageBoxText);
|
||
|
|
idEmpty.exec();
|
||
|
|
}
|
||
|
|
|
||
|
|
void exit()
|
||
|
|
{
|
||
|
|
QApplication::quit();
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
#endif
|