内存错误调完了
parent
0483fe84f9
commit
6255beecea
Binary file not shown.
|
@ -15,8 +15,6 @@ MyButton::MyButton(ButtonStruct &buttonStruct,int width,int height,QList<MyButto
|
|||
}
|
||||
|
||||
MyButton::~MyButton() {
|
||||
delete logo;
|
||||
delete logo_cover;
|
||||
}
|
||||
|
||||
void MyButton::paintEvent(QPaintEvent *e) {
|
||||
|
@ -33,13 +31,17 @@ void MyButton::paintEvent(QPaintEvent *e) {
|
|||
int text_y=(logo_width+logo_y+10);
|
||||
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);
|
||||
painter.setPen(QColor("#FFFFFF"));
|
||||
painter.drawImage(logo_rect, *logo);
|
||||
painter.drawText(text_rect, Qt::AlignCenter, text);
|
||||
|
||||
if(checked){
|
||||
QRectF rect(0, this->height()-6, this->width(), 5);
|
||||
painter.fillRect(rect, QColor("#FFFFFF"));
|
||||
}
|
||||
painter.setPen(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 {
|
||||
|
|
|
@ -76,7 +76,7 @@
|
|||
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
|
|
|
@ -4,9 +4,9 @@
|
|||
|
||||
#ifndef OFFICEASSISTANT_CONFIG_H
|
||||
#define OFFICEASSISTANT_CONFIG_H
|
||||
#define CONFIG_URL "http://apisoft.s103.y01.cn/addons/Kmdsoft/Index/config"
|
||||
#define OP_URL "http://apisoft.s103.y01.cn/addons/Kmdsoft/Index/op"
|
||||
#define DEVICE_URL "http://apisoft.s103.y01.cn/addons/Kmdsoft/Index/device"
|
||||
#define BASE_URL "http://apisoft.s103.y01.cn/"
|
||||
#define DEFAULT_FILE "/config/default.kmd"
|
||||
#define CONFIG_URL "http://softapi.s103.y01.cn/addons/Kmdsoft/Index/config"
|
||||
#define OP_URL "http://softapi.s103.y01.cn/addons/Kmdsoft/Index/op"
|
||||
#define DEVICE_URL "http://softapi.s103.y01.cn/addons/Kmdsoft/Index/device"
|
||||
#define BASE_URL "http://softapi.s103.y01.cn/"
|
||||
#define DEFAULT_FILE "/config/default_navbar.kmd"
|
||||
#endif //OFFICEASSISTANT_CONFIG_H
|
||||
|
|
|
@ -11,6 +11,7 @@ MainWindowLayout::MainWindowLayout(QWidget *parent) :
|
|||
QWidget(parent), ui(new Ui::MainWindowLayout) {
|
||||
ui->setupUi(this);
|
||||
layout=new QVBoxLayout(this);
|
||||
mainWindowLayout = this;
|
||||
ConfigRequest *configRequest = new ConfigRequest;
|
||||
ConfigResponse *configResponse = new ConfigResponse;
|
||||
configRequest->sendRequest(configResponse);
|
||||
|
@ -26,7 +27,7 @@ MainWindowLayout::MainWindowLayout(QWidget *parent) :
|
|||
|
||||
MainWindowLayout::~MainWindowLayout() {
|
||||
|
||||
delete[] list[0];
|
||||
//delete[] list[0];
|
||||
delete navBar;
|
||||
//delete layout;
|
||||
delete ui;
|
||||
|
|
|
@ -33,7 +33,7 @@ protected:
|
|||
private:
|
||||
Ui::MainWindowLayout *ui;
|
||||
QVBoxLayout *layout;
|
||||
QList<ButtonStruct *> list;
|
||||
//QList<ButtonStruct *> list;
|
||||
NavBar *navBar;
|
||||
ButtonStruct *buttons;
|
||||
MainScreen *mainScreen;
|
||||
|
|
|
@ -19,12 +19,13 @@
|
|||
NavBar::NavBar(ConfigResponse *configResponse,QWidget *parent) :
|
||||
QWidget(parent), ui(new Ui::NavBar) {
|
||||
ui->setupUi(this);
|
||||
if (configResponse->succeed) {
|
||||
buffer = new QByteArray;
|
||||
if (configResponse->succeed&&configResponse->menus.empty()!=true) {
|
||||
getLogoFromInternet(configResponse);
|
||||
}
|
||||
else {
|
||||
getLogoFromLocal();
|
||||
};
|
||||
}
|
||||
int n = buttonStructs.length();
|
||||
int x = (width() - height()*n) / 2;
|
||||
for (auto buttonStruct : buttonStructs) {
|
||||
|
@ -83,6 +84,7 @@ void NavBar::getLogoFromInternet(ConfigResponse *configResponse) {
|
|||
connect(reply, &QNetworkReply::finished, &eventLoop,&QEventLoop::quit);
|
||||
connect(&timer, &QTimer::timeout,this, &NavBar::cancelDownload);
|
||||
timer.stop();
|
||||
buffer = new QByteArray;
|
||||
delete request_logo;
|
||||
if (downloadSuccess == true) {
|
||||
*buffer = reply->readAll();
|
||||
|
@ -91,7 +93,7 @@ void NavBar::getLogoFromInternet(ConfigResponse *configResponse) {
|
|||
QPainter painter_logo(logo);
|
||||
render_logo->render(&painter_logo);
|
||||
buffer->clear();
|
||||
for (auto button : *configResponse->menus) {
|
||||
for (auto button : configResponse->menus) {
|
||||
QUrl url_image(QString(BASE_URL) + button.img);
|
||||
QNetworkRequest *request_image = new QNetworkRequest(url_image);
|
||||
reply = manager->get(*request_image);
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include <QGuiApplication>
|
||||
#include <QApplication>
|
||||
#include <ctime>
|
||||
#include <qDebug>
|
||||
#pragma comment(lib, "wbemuuid.lib")
|
||||
#ifdef _DEBUG
|
||||
#pragma comment(lib, "Qt5Networkd.lib")
|
||||
|
@ -47,7 +48,7 @@ RequestBodyBase::RequestBodyBase(){
|
|||
QString request_id=QString::fromWCharArray(unix_time);
|
||||
//打开配置文件
|
||||
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)){
|
||||
QMessageBox::critical(nullptr,QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("无法打开配置文件"));
|
||||
delete infFile;
|
||||
|
@ -83,18 +84,14 @@ RequestBodyBase::RequestBodyBase(){
|
|||
exit(1);
|
||||
}
|
||||
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();
|
||||
}else{
|
||||
//处理错误
|
||||
QMessageBox::warning(nullptr,"错误","配置文件损坏");
|
||||
QMessageBox::warning(nullptr, QString::fromLocal8Bit("´íÎó"), QString::fromLocal8Bit("ÅäÖÃÎļþËð»µ"));
|
||||
exit(1);
|
||||
}
|
||||
//获取操作系统版本
|
||||
os="Windows";
|
||||
this->os="Windows";
|
||||
OSVERSIONINFOEX os;
|
||||
os.dwOSVersionInfoSize=sizeof(os);
|
||||
GetVersionEx((OSVERSIONINFO *)&os);
|
||||
|
@ -130,7 +127,7 @@ RequestBodyBase::RequestBodyBase(){
|
|||
//读取MachineGUID并取MD5作为device_id
|
||||
QByteArray hash = QCryptographicHash::hash(getMachineGUID().toUtf8(), QCryptographicHash::Md5);
|
||||
device_id=hash.toHex();
|
||||
infFile=new QFile(".\\config\\information.kmd");
|
||||
infFile=new QFile(dir + "/config/information.kmd");
|
||||
if(!infFile->open(QIODevice::WriteOnly|QIODevice::Text)){
|
||||
//处理错误
|
||||
QMessageBox::warning(nullptr, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("无法覆写配置文件"));
|
||||
|
@ -140,7 +137,7 @@ RequestBodyBase::RequestBodyBase(){
|
|||
}
|
||||
//加入json序列
|
||||
QJsonValue value=device_id;
|
||||
QJsonObject obj_root;
|
||||
QJsonObject obj_root = qJsonDocument.object();
|
||||
obj_root.insert("device_id",value);
|
||||
qJsonDocument.setObject(obj_root);
|
||||
//写入配置文件
|
||||
|
@ -149,25 +146,24 @@ RequestBodyBase::RequestBodyBase(){
|
|||
infFile->close();
|
||||
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);
|
||||
QJsonObject obj_root;
|
||||
QJsonObject obj_root=qJsonDocument.object();
|
||||
//插入request_id
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ConfigRequest::sendRequest(ConfigResponse *configResponse) {
|
||||
timer = new QTimer(this);
|
||||
timer = new QTimer(this);
|
||||
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;
|
||||
//HTTP请求
|
||||
//请求头
|
||||
|
@ -175,33 +171,40 @@ void ConfigRequest::sendRequest(ConfigResponse *configResponse) {
|
|||
requestInfo.setHeader(QNetworkRequest::ContentTypeHeader,QVariant("application/json"));
|
||||
//保存响应的变量
|
||||
reply = httpMgr->post(requestInfo,qJsonDocument.toJson());
|
||||
qDebug() << qJsonDocument.toJson();
|
||||
//开启一个循环,直到超时或者获取到数据为止
|
||||
connect(reply,&QNetworkReply::finished, &eventLoop, &QEventLoop::quit);
|
||||
//设置定时器防止超时
|
||||
connect(timer,&QTimer::timeout,this,&ConfigRequest::cancelDownload);
|
||||
timer->start(5000);
|
||||
//启动循环
|
||||
eventLoop.exec();
|
||||
delete httpMgr;
|
||||
eventLoop.exec();
|
||||
timer->stop();
|
||||
//delete httpMgr;
|
||||
QJsonDocument result;
|
||||
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) {
|
||||
result = QJsonDocument::fromJson(reply->readAll());
|
||||
}else{
|
||||
//如果有错误
|
||||
configResponse->succeed=false;
|
||||
delete reply;
|
||||
//delete reply;
|
||||
delete timer;
|
||||
delete httpMgr;
|
||||
return;
|
||||
}
|
||||
qDebug() << result.toJson();
|
||||
|
||||
//如果数据完整
|
||||
if(result.isObject()){
|
||||
QJsonObject obj_root=result.object();
|
||||
QJsonArray array;
|
||||
array = obj_root.value("menu").toArray();
|
||||
configResponse->menus=new QList<Menu>;
|
||||
|
||||
auto i=0;
|
||||
for(auto value:array){
|
||||
QJsonObject object=value.toObject();
|
||||
|
@ -211,16 +214,18 @@ void ConfigRequest::sendRequest(ConfigResponse *configResponse) {
|
|||
menu.title=object.value("title").toString();
|
||||
menu.func=object.value("func").toString();
|
||||
menu.url=object.value("url").toString();
|
||||
*configResponse->menus << menu;
|
||||
configResponse->menus << menu;
|
||||
i++;
|
||||
}
|
||||
}else{
|
||||
//数据不完整
|
||||
configResponse->succeed=false;
|
||||
delete reply;
|
||||
//delete reply;
|
||||
delete timer;
|
||||
delete httpMgr;
|
||||
return;
|
||||
}
|
||||
delete httpMgr;
|
||||
}
|
||||
void RequestBodyBase::cancelDownload() {
|
||||
disconnect(reply, &QNetworkReply::finished, &eventLoop, &QEventLoop::quit);
|
||||
|
|
|
@ -32,7 +32,7 @@ typedef struct {
|
|||
QString title_color;
|
||||
QString title_cover_color;
|
||||
}basic;
|
||||
QList<Menu> *menus;
|
||||
QList<Menu> menus;
|
||||
}ConfigResponse;
|
||||
|
||||
class RequestBodyBase:public QObject{
|
||||
|
|
Loading…
Reference in New Issue