This commit is contained in:
zhuzichu 2023-07-24 18:23:26 +08:00
parent db805ef85d
commit be7b2dcc34
4 changed files with 67 additions and 21 deletions

View File

@ -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"
@ -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{
}
}
}
}

View File

@ -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();

View File

@ -94,3 +94,7 @@ void FluTools::deleteItem(QObject *p){
p = nullptr;
}
}
QString FluTools::toLocalPath(const QUrl& url){
return url.toLocalFile();
}

View File

@ -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
@ -42,23 +73,37 @@ public:
*/
Q_INVOKABLE QString readFile(const QString& fileName);
Q_INVOKABLE bool isMacos();
Q_INVOKABLE bool isLinux();
Q_INVOKABLE bool isWin();
/**
* @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