内存错误调完了

master
Mike Solar 2023-07-30 13:57:54 +08:00
parent 0483fe84f9
commit 6255beecea
9 changed files with 55 additions and 45 deletions

Binary file not shown.

View File

@ -15,8 +15,6 @@ MyButton::MyButton(ButtonStruct &buttonStruct,int width,int height,QList<MyButto
} }
MyButton::~MyButton() { MyButton::~MyButton() {
delete logo;
delete logo_cover;
} }
void MyButton::paintEvent(QPaintEvent *e) { void MyButton::paintEvent(QPaintEvent *e) {
@ -33,13 +31,17 @@ void MyButton::paintEvent(QPaintEvent *e) {
int text_y=(logo_width+logo_y+10); int text_y=(logo_width+logo_y+10);
QRectF logo_rect(logo_x, logo_y, logo_width, logo_width); QRectF logo_rect(logo_x, logo_y, logo_width, logo_width);
QRectF text_rect(text_x,text_y, TEXT_SIZE*text.length()*scale*2,TEXT_SIZE*scale*2); QRectF text_rect(text_x,text_y, TEXT_SIZE*text.length()*scale*2,TEXT_SIZE*scale*2);
painter.setPen(QColor("#FFFFFF"));
painter.drawImage(logo_rect, *logo);
painter.drawText(text_rect, Qt::AlignCenter, text);
if(checked){ if(checked){
QRectF rect(0, this->height()-6, this->width(), 5); painter.setPen(QColor("#FFFFFF"));
painter.fillRect(rect, QColor("#FFFFFF")); painter.drawImage(logo_rect, *logo_cover);
} painter.drawText(text_rect, Qt::AlignCenter, text);
}
else {
painter.setPen(QColor("#FFFFFF"));
painter.drawImage(logo_rect, *logo);
painter.drawText(text_rect, Qt::AlignCenter, text);
}
} }
QSize MyButton::sizeHint() const { QSize MyButton::sizeHint() const {

View File

@ -76,7 +76,7 @@
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary> <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Windows</SubSystem> <SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>

View File

@ -4,9 +4,9 @@
#ifndef OFFICEASSISTANT_CONFIG_H #ifndef OFFICEASSISTANT_CONFIG_H
#define OFFICEASSISTANT_CONFIG_H #define OFFICEASSISTANT_CONFIG_H
#define CONFIG_URL "http://apisoft.s103.y01.cn/addons/Kmdsoft/Index/config" #define CONFIG_URL "http://softapi.s103.y01.cn/addons/Kmdsoft/Index/config"
#define OP_URL "http://apisoft.s103.y01.cn/addons/Kmdsoft/Index/op" #define OP_URL "http://softapi.s103.y01.cn/addons/Kmdsoft/Index/op"
#define DEVICE_URL "http://apisoft.s103.y01.cn/addons/Kmdsoft/Index/device" #define DEVICE_URL "http://softapi.s103.y01.cn/addons/Kmdsoft/Index/device"
#define BASE_URL "http://apisoft.s103.y01.cn/" #define BASE_URL "http://softapi.s103.y01.cn/"
#define DEFAULT_FILE "/config/default.kmd" #define DEFAULT_FILE "/config/default_navbar.kmd"
#endif //OFFICEASSISTANT_CONFIG_H #endif //OFFICEASSISTANT_CONFIG_H

View File

@ -11,6 +11,7 @@ MainWindowLayout::MainWindowLayout(QWidget *parent) :
QWidget(parent), ui(new Ui::MainWindowLayout) { QWidget(parent), ui(new Ui::MainWindowLayout) {
ui->setupUi(this); ui->setupUi(this);
layout=new QVBoxLayout(this); layout=new QVBoxLayout(this);
mainWindowLayout = this;
ConfigRequest *configRequest = new ConfigRequest; ConfigRequest *configRequest = new ConfigRequest;
ConfigResponse *configResponse = new ConfigResponse; ConfigResponse *configResponse = new ConfigResponse;
configRequest->sendRequest(configResponse); configRequest->sendRequest(configResponse);
@ -26,7 +27,7 @@ MainWindowLayout::MainWindowLayout(QWidget *parent) :
MainWindowLayout::~MainWindowLayout() { MainWindowLayout::~MainWindowLayout() {
delete[] list[0]; //delete[] list[0];
delete navBar; delete navBar;
//delete layout; //delete layout;
delete ui; delete ui;

View File

@ -33,7 +33,7 @@ protected:
private: private:
Ui::MainWindowLayout *ui; Ui::MainWindowLayout *ui;
QVBoxLayout *layout; QVBoxLayout *layout;
QList<ButtonStruct *> list; //QList<ButtonStruct *> list;
NavBar *navBar; NavBar *navBar;
ButtonStruct *buttons; ButtonStruct *buttons;
MainScreen *mainScreen; MainScreen *mainScreen;

View File

@ -19,12 +19,13 @@
NavBar::NavBar(ConfigResponse *configResponse,QWidget *parent) : NavBar::NavBar(ConfigResponse *configResponse,QWidget *parent) :
QWidget(parent), ui(new Ui::NavBar) { QWidget(parent), ui(new Ui::NavBar) {
ui->setupUi(this); ui->setupUi(this);
if (configResponse->succeed) { buffer = new QByteArray;
if (configResponse->succeed&&configResponse->menus.empty()!=true) {
getLogoFromInternet(configResponse); getLogoFromInternet(configResponse);
} }
else { else {
getLogoFromLocal(); getLogoFromLocal();
}; }
int n = buttonStructs.length(); int n = buttonStructs.length();
int x = (width() - height()*n) / 2; int x = (width() - height()*n) / 2;
for (auto buttonStruct : buttonStructs) { for (auto buttonStruct : buttonStructs) {
@ -83,6 +84,7 @@ void NavBar::getLogoFromInternet(ConfigResponse *configResponse) {
connect(reply, &QNetworkReply::finished, &eventLoop,&QEventLoop::quit); connect(reply, &QNetworkReply::finished, &eventLoop,&QEventLoop::quit);
connect(&timer, &QTimer::timeout,this, &NavBar::cancelDownload); connect(&timer, &QTimer::timeout,this, &NavBar::cancelDownload);
timer.stop(); timer.stop();
buffer = new QByteArray;
delete request_logo; delete request_logo;
if (downloadSuccess == true) { if (downloadSuccess == true) {
*buffer = reply->readAll(); *buffer = reply->readAll();
@ -91,7 +93,7 @@ void NavBar::getLogoFromInternet(ConfigResponse *configResponse) {
QPainter painter_logo(logo); QPainter painter_logo(logo);
render_logo->render(&painter_logo); render_logo->render(&painter_logo);
buffer->clear(); buffer->clear();
for (auto button : *configResponse->menus) { for (auto button : configResponse->menus) {
QUrl url_image(QString(BASE_URL) + button.img); QUrl url_image(QString(BASE_URL) + button.img);
QNetworkRequest *request_image = new QNetworkRequest(url_image); QNetworkRequest *request_image = new QNetworkRequest(url_image);
reply = manager->get(*request_image); reply = manager->get(*request_image);

View File

@ -21,6 +21,7 @@
#include <QGuiApplication> #include <QGuiApplication>
#include <QApplication> #include <QApplication>
#include <ctime> #include <ctime>
#include <qDebug>
#pragma comment(lib, "wbemuuid.lib") #pragma comment(lib, "wbemuuid.lib")
#ifdef _DEBUG #ifdef _DEBUG
#pragma comment(lib, "Qt5Networkd.lib") #pragma comment(lib, "Qt5Networkd.lib")
@ -47,7 +48,7 @@ RequestBodyBase::RequestBodyBase(){
QString request_id=QString::fromWCharArray(unix_time); QString request_id=QString::fromWCharArray(unix_time);
//打开配置文件 //打开配置文件
QString dir=QApplication::applicationDirPath(); QString dir=QApplication::applicationDirPath();
QFile *infFile=new QFile(dir+"config/information.kmd"); QFile *infFile=new QFile(dir+"/config/information.kmd");
if(!infFile->open(QIODevice::ReadOnly|QIODevice::Text)){ if(!infFile->open(QIODevice::ReadOnly|QIODevice::Text)){
QMessageBox::critical(nullptr,QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("无法打开配置文件")); QMessageBox::critical(nullptr,QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("无法打开配置文件"));
delete infFile; delete infFile;
@ -83,18 +84,14 @@ RequestBodyBase::RequestBodyBase(){
exit(1); exit(1);
} }
version=obj_root.value("version").toString(); version=obj_root.value("version").toString();
if(obj_root.value("device_id")==QJsonValue::Undefined){
QMessageBox::warning(nullptr, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("配置文件损坏"));
exit(1);
}
device_id=obj_root.value("device_id").toString(); device_id=obj_root.value("device_id").toString();
}else{ }else{
//处理错误 //处理错误
QMessageBox::warning(nullptr,"错误","配置文件损坏"); QMessageBox::warning(nullptr, QString::fromLocal8Bit("´íÎó"), QString::fromLocal8Bit("ÅäÖÃÎļþËð»µ"));
exit(1); exit(1);
} }
//获取操作系统版本 //获取操作系统版本
os="Windows"; this->os="Windows";
OSVERSIONINFOEX os; OSVERSIONINFOEX os;
os.dwOSVersionInfoSize=sizeof(os); os.dwOSVersionInfoSize=sizeof(os);
GetVersionEx((OSVERSIONINFO *)&os); GetVersionEx((OSVERSIONINFO *)&os);
@ -130,7 +127,7 @@ RequestBodyBase::RequestBodyBase(){
//读取MachineGUID并取MD5作为device_id //读取MachineGUID并取MD5作为device_id
QByteArray hash = QCryptographicHash::hash(getMachineGUID().toUtf8(), QCryptographicHash::Md5); QByteArray hash = QCryptographicHash::hash(getMachineGUID().toUtf8(), QCryptographicHash::Md5);
device_id=hash.toHex(); device_id=hash.toHex();
infFile=new QFile(".\\config\\information.kmd"); infFile=new QFile(dir + "/config/information.kmd");
if(!infFile->open(QIODevice::WriteOnly|QIODevice::Text)){ if(!infFile->open(QIODevice::WriteOnly|QIODevice::Text)){
//处理错误 //处理错误
QMessageBox::warning(nullptr, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("无法覆写配置文件")); QMessageBox::warning(nullptr, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("无法覆写配置文件"));
@ -140,7 +137,7 @@ RequestBodyBase::RequestBodyBase(){
} }
//加入json序列 //加入json序列
QJsonValue value=device_id; QJsonValue value=device_id;
QJsonObject obj_root; QJsonObject obj_root = qJsonDocument.object();
obj_root.insert("device_id",value); obj_root.insert("device_id",value);
qJsonDocument.setObject(obj_root); qJsonDocument.setObject(obj_root);
//写入配置文件 //写入配置文件
@ -149,25 +146,24 @@ RequestBodyBase::RequestBodyBase(){
infFile->close(); infFile->close();
delete infFile; delete infFile;
} }
QJsonValue os_json(this->os);
QJsonValue os_version_json(this->os_version);
QJsonValue sign_json(QString("123456789890"));
QJsonValue requestId_json=QJsonValue(request_id); QJsonValue requestId_json=QJsonValue(request_id);
QJsonObject obj_root; QJsonObject obj_root=qJsonDocument.object();
//插入request_id //插入request_id
obj_root.insert("request_id",requestId_json); obj_root.insert("request_id",requestId_json);
obj_root.insert("os", os_json);
obj_root.insert("os_version", os_version_json);
obj_root.insert("sign", sign_json);
qJsonDocument.setObject(obj_root); qJsonDocument.setObject(obj_root);
} }
void ConfigRequest::sendRequest(ConfigResponse *configResponse) { void ConfigRequest::sendRequest(ConfigResponse *configResponse) {
timer = new QTimer(this); timer = new QTimer(this);
QNetworkAccessManager *httpMgr = new QNetworkAccessManager(); QNetworkAccessManager *httpMgr = new QNetworkAccessManager();
/* QFile *file=new QFile(".\\config\\config.cfg");
if(!file->open(QIODevice::ReadOnly|QIODevice::Text)){
QMessageBox::warning(nullptr,"错误","无法打开配置文件");
file->close();
delete file;
exit(1);
}*/
QNetworkRequest requestInfo; QNetworkRequest requestInfo;
//HTTP请求 //HTTP请求
//请求头 //请求头
@ -175,33 +171,40 @@ void ConfigRequest::sendRequest(ConfigResponse *configResponse) {
requestInfo.setHeader(QNetworkRequest::ContentTypeHeader,QVariant("application/json")); requestInfo.setHeader(QNetworkRequest::ContentTypeHeader,QVariant("application/json"));
//保存响应的变量 //保存响应的变量
reply = httpMgr->post(requestInfo,qJsonDocument.toJson()); reply = httpMgr->post(requestInfo,qJsonDocument.toJson());
qDebug() << qJsonDocument.toJson();
//开启一个循环,直到超时或者获取到数据为止 //开启一个循环,直到超时或者获取到数据为止
connect(reply,&QNetworkReply::finished, &eventLoop, &QEventLoop::quit); connect(reply,&QNetworkReply::finished, &eventLoop, &QEventLoop::quit);
//设置定时器防止超时 //设置定时器防止超时
connect(timer,&QTimer::timeout,this,&ConfigRequest::cancelDownload); connect(timer,&QTimer::timeout,this,&ConfigRequest::cancelDownload);
timer->start(5000); timer->start(5000);
//启动循环 //启动循环
eventLoop.exec(); eventLoop.exec();
delete httpMgr; timer->stop();
//delete httpMgr;
QJsonDocument result; QJsonDocument result;
configResponse=new ConfigResponse; configResponse=new ConfigResponse;
memset(configResponse,0,sizeof(*configResponse)); configResponse->succeed = false;
//memset(configResponse,0,sizeof(*configResponse));
auto error = reply->error();
//如果没有错误 //如果没有错误
if(reply->error() == QNetworkReply::NoError) { if(reply->error() == QNetworkReply::NoError) {
result = QJsonDocument::fromJson(reply->readAll()); result = QJsonDocument::fromJson(reply->readAll());
}else{ }else{
//如果有错误 //如果有错误
configResponse->succeed=false; configResponse->succeed=false;
delete reply; //delete reply;
delete timer; delete timer;
delete httpMgr;
return; return;
} }
qDebug() << result.toJson();
//如果数据完整 //如果数据完整
if(result.isObject()){ if(result.isObject()){
QJsonObject obj_root=result.object(); QJsonObject obj_root=result.object();
QJsonArray array; QJsonArray array;
array = obj_root.value("menu").toArray(); array = obj_root.value("menu").toArray();
configResponse->menus=new QList<Menu>;
auto i=0; auto i=0;
for(auto value:array){ for(auto value:array){
QJsonObject object=value.toObject(); QJsonObject object=value.toObject();
@ -211,16 +214,18 @@ void ConfigRequest::sendRequest(ConfigResponse *configResponse) {
menu.title=object.value("title").toString(); menu.title=object.value("title").toString();
menu.func=object.value("func").toString(); menu.func=object.value("func").toString();
menu.url=object.value("url").toString(); menu.url=object.value("url").toString();
*configResponse->menus << menu; configResponse->menus << menu;
i++; i++;
} }
}else{ }else{
//数据不完整 //数据不完整
configResponse->succeed=false; configResponse->succeed=false;
delete reply; //delete reply;
delete timer; delete timer;
delete httpMgr;
return; return;
} }
delete httpMgr;
} }
void RequestBodyBase::cancelDownload() { void RequestBodyBase::cancelDownload() {
disconnect(reply, &QNetworkReply::finished, &eventLoop, &QEventLoop::quit); disconnect(reply, &QNetworkReply::finished, &eventLoop, &QEventLoop::quit);

View File

@ -32,7 +32,7 @@ typedef struct {
QString title_color; QString title_color;
QString title_cover_color; QString title_cover_color;
}basic; }basic;
QList<Menu> *menus; QList<Menu> menus;
}ConfigResponse; }ConfigResponse;
class RequestBodyBase:public QObject{ class RequestBodyBase:public QObject{