From c23e81601755944aadba5527249fc04360f03a6c Mon Sep 17 00:00:00 2001 From: RigoLigoRLC Date: Sat, 26 Sep 2020 01:19:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20=E4=B8=8B=E8=BD=BDapp.json?= =?UTF-8?q?=E6=88=96=E5=9B=BE=E6=A0=87=E5=A4=B1=E8=B4=A5=E5=B0=86=E7=BB=99?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=8F=91=E9=80=81=E6=8F=90=E9=86=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 这里改变了widget这个类里面loadappinfo的返回值,使处理异常返回状态可以实现 --- widget.cpp | 33 +++++++++++++++++++++++++++------ widget.h | 2 +- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/widget.cpp b/widget.cpp index 0299a3e..200e25e 100644 --- a/widget.cpp +++ b/widget.cpp @@ -412,10 +412,10 @@ void Widget::updatefoot() ui->webfoot->setFixedHeight(allh-foot); } -void Widget::loadappinfo(QUrl arg1) +int Widget::loadappinfo(QUrl arg1) { if(arg1.isEmpty()){ - return; + return 1; } // 先隐藏详情页负责显示截图的label @@ -447,6 +447,9 @@ void Widget::loadappinfo(QUrl arg1) get_json.start("curl -o app.json "+arg1.toString()); get_json.waitForFinished(); + if(get_json.exitCode()) + return 2; + QFile app_json("app.json"); if(app_json.open(QIODevice::ReadOnly)){ // 成功得到json文件 @@ -526,9 +529,13 @@ void Widget::loadappinfo(QUrl arg1) // 图标加载 get_json.start("curl -o icon.png "+urladdress+"icon.png"); get_json.waitForFinished(); - QPixmap appicon(QString::fromUtf8(TMP_PATH)+"/icon.png"); - ui->label_appicon->setPixmap(appicon); - ui->pushButton_download->setEnabled(true); + if(!get_json.exitCode()) { + QPixmap appicon(QString::fromUtf8(TMP_PATH)+"/icon.png"); + ui->label_appicon->setPixmap(appicon); + ui->pushButton_download->setEnabled(true); + } + else + system("notify-send 应用程序图标加载失败 --icon=spark-store"); // 截图展示加载 @@ -562,6 +569,7 @@ void Widget::loadappinfo(QUrl arg1) ui->label_show->setText(""); ui->label_show->hide(); } + return 0; } void Widget::on_pushButton_download_clicked() @@ -906,7 +914,20 @@ void Widget::on_webEngineView_urlChanged(const QUrl &arg1) load.cancel();//打开并发加载线程前关闭正在执行的线程 load = QtConcurrent::run([=](){ - loadappinfo(arg1); + int loadresult = loadappinfo(arg1); + if(!loadresult) + return; + else { + switch(loadresult) + { + case 1: // 空的arg1 + //此处不应通知用户 + break; + case 2: // curl下载app.json失败 + system("notify-send 应用程序详细信息下载失败,请检查网络连接 --icon=spark-store"); + break; + } + } }); } } diff --git a/widget.h b/widget.h index 040fb32..6a0fb44 100644 --- a/widget.h +++ b/widget.h @@ -96,7 +96,7 @@ public: private: void initUI(); void initConfig(); - void loadappinfo(QUrl); + int loadappinfo(QUrl); void chooseLeftMenu(int index); void setfoot(int); void updatefoot();