From be7b2dcc34ab807efdaaae6523049386b8c4d441 Mon Sep 17 00:00:00 2001 From: zhuzichu Date: Mon, 24 Jul 2023 18:23:26 +0800 Subject: [PATCH] update --- example/qml/page/T_Http.qml | 12 ++----- src/FluHttp.cpp | 5 +++ src/FluTools.cpp | 4 +++ src/FluTools.h | 67 +++++++++++++++++++++++++++++++------ 4 files changed, 67 insertions(+), 21 deletions(-) diff --git a/example/qml/page/T_Http.qml b/example/qml/page/T_Http.qml index 199ec9ba..ee18fd90 100644 --- a/example/qml/page/T_Http.qml +++ b/example/qml/page/T_Http.qml @@ -11,10 +11,6 @@ FluScrollablePage{ title:"Http" - Component.onDestruction: { - console.debug("T_Http -> onDestruction") - } - FluHttp{ id:http_get url:"https://api.github.com/search/repositories" @@ -60,7 +56,7 @@ FluScrollablePage{ FluHttp{ id:http_download url:"http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4" -// url:"https://www.w3school.com.cn/example/html5/mov_bbb.mp4" + // url:"https://www.w3school.com.cn/example/html5/mov_bbb.mp4" onStart: { btn_download.disabled = true } @@ -119,7 +115,7 @@ FluScrollablePage{ id: file_dialog currentFolder: StandardPaths.standardLocations(StandardPaths.DownloadLocation)[0] onAccepted: { - var path = currentFolder.toString().replace(FluTools.isMacos() ? "file://" : "file:///","") + "/big_buck_bunny.mp4" + var path = FluTools.toLocalPath(currentFolder)+ "/big_buck_bunny.mp4" http_download.download(path) } } @@ -131,7 +127,6 @@ FluScrollablePage{ height: 400 Item{ anchors.fill: parent - Flickable{ id:scrollview width: parent.width @@ -149,7 +144,4 @@ FluScrollablePage{ } } } - - - } diff --git a/src/FluHttp.cpp b/src/FluHttp.cpp index c3cf5b3f..47f88543 100644 --- a/src/FluHttp.cpp +++ b/src/FluHttp.cpp @@ -65,6 +65,7 @@ void FluHttp::post(QVariantMap params,QVariantMap headers){ int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); QString errorString = reply->errorString(); bool isSuccess = reply->error() == QNetworkReply::NoError; + _cache.removeOne(reply); reply->deleteLater(); reply = nullptr; if (isSuccess) { @@ -101,6 +102,7 @@ void FluHttp::postString(QString params,QVariantMap headers){ int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); QString errorString = reply->errorString(); bool isSuccess = reply->error() == QNetworkReply::NoError; + _cache.removeOne(reply); reply->deleteLater(); reply = nullptr; if (isSuccess) { @@ -139,6 +141,7 @@ void FluHttp::postJson(QVariantMap params,QVariantMap headers){ int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); QString errorString = reply->errorString(); bool isSuccess = reply->error() == QNetworkReply::NoError; + _cache.removeOne(reply); reply->deleteLater(); reply = nullptr; if (isSuccess) { @@ -176,6 +179,7 @@ void FluHttp::get(QVariantMap params,QVariantMap headers){ int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); QString errorString = reply->errorString(); bool isSuccess = reply->error() == QNetworkReply::NoError; + _cache.removeOne(reply); reply->deleteLater(); reply = nullptr; if (isSuccess) { @@ -228,6 +232,7 @@ void FluHttp::download(QString path,QVariantMap params,QVariantMap headers){ }else{ Q_EMIT error(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(),reply->errorString()); } + _cache.removeOne(reply); file->close(); file->deleteLater(); reply->deleteLater(); diff --git a/src/FluTools.cpp b/src/FluTools.cpp index e8e3e819..d1364878 100644 --- a/src/FluTools.cpp +++ b/src/FluTools.cpp @@ -94,3 +94,7 @@ void FluTools::deleteItem(QObject *p){ p = nullptr; } } + +QString FluTools::toLocalPath(const QUrl& url){ + return url.toLocalFile(); +} diff --git a/src/FluTools.h b/src/FluTools.h index a045e043..15d45c84 100644 --- a/src/FluTools.h +++ b/src/FluTools.h @@ -23,6 +23,37 @@ public: return getInstance(); } static FluTools *getInstance(); + + /** + * @brief qtMajor Qt Major版本 + * @return + */ + Q_INVOKABLE int qtMajor(); + + /** + * @brief qtMajor Qt Minor版本 + * @return + */ + Q_INVOKABLE int qtMinor(); + + /** + * @brief isMacos 是否是Macos系统 + * @return + */ + Q_INVOKABLE bool isMacos(); + + /** + * @brief isLinux 是否是Linux系统 + * @return + */ + Q_INVOKABLE bool isLinux(); + + /** + * @brief isWin 是否是Windows系统 + * @return + */ + Q_INVOKABLE bool isWin(); + /** * @brief clipText 将字符串添加到剪切板 * @param text @@ -40,25 +71,39 @@ public: * @param fileName * @return */ - Q_INVOKABLE QString readFile(const QString &fileName); - - Q_INVOKABLE bool isMacos(); - - Q_INVOKABLE bool isLinux(); - - Q_INVOKABLE bool isWin(); + Q_INVOKABLE QString readFile(const QString& fileName); + /** + * @brief setQuitOnLastWindowClosed 设置关闭最后一个窗口是否退出程序 + * @param val + */ Q_INVOKABLE void setQuitOnLastWindowClosed(bool val); - Q_INVOKABLE int qtMajor(); - - Q_INVOKABLE int qtMinor(); - + /** + * @brief setOverrideCursor 设置全局鼠标样式 + * @param shape + */ Q_INVOKABLE void setOverrideCursor(Qt::CursorShape shape); + /** + * @brief restoreOverrideCursor 还原全局鼠标样式 + */ Q_INVOKABLE void restoreOverrideCursor(); + /** + * @brief toLocalPath 获取文件路径,可以去掉windows系统下的file:///,macos下的file:// + * @param url + * @return 返回文件路径 + */ + Q_INVOKABLE QString toLocalPath(const QUrl& url); + + /** + * @brief deleteItem 销毁Item对象 + * @param p + */ Q_INVOKABLE void deleteItem(QObject *p); + + }; #endif // FLUTOOLS_H