diff --git a/doric-Qt/example/app/main.qml b/doric-Qt/example/app/main.qml index 508ec167..55f4ab8b 100644 --- a/doric-Qt/example/app/main.qml +++ b/doric-Qt/example/app/main.qml @@ -1,6 +1,6 @@ import QtQuick 2.12 import QtQuick.Controls 2.5 -import QtQuick.Layouts 1.15 +import QtQuick.Layouts 1.14 ApplicationWindow { visible: true diff --git a/doric-Qt/example/doric/doric.pro b/doric-Qt/example/doric/doric.pro index fb6c4e2c..91e1c170 100644 --- a/doric-Qt/example/doric/doric.pro +++ b/doric-Qt/example/doric/doric.pro @@ -179,6 +179,7 @@ HEADERS += \ utils/DoricSwitchBridge.h \ utils/DoricThreadMode.h \ utils/DoricUtils.h \ + utils/ReplyTimeout.h \ widget/flex/FlexLayout.h \ widget/flex/FlexLayoutConfig.h \ widget/flex/FlexLayoutService.h \ diff --git a/doric-Qt/example/doric/resources/draggable.qml b/doric-Qt/example/doric/resources/draggable.qml index 889f90b1..c2dcc35e 100644 --- a/doric-Qt/example/doric/resources/draggable.qml +++ b/doric-Qt/example/doric/resources/draggable.qml @@ -1,6 +1,6 @@ import QtQuick 2.12 import QtQuick.Controls 2.5 -import QtQuick.Layouts 1.15 +import QtQuick.Layouts 1.14 import QtGraphicalEffects 1.12 import "util.mjs" as Util diff --git a/doric-Qt/example/doric/resources/flex.qml b/doric-Qt/example/doric/resources/flex.qml index b6dac544..90d8c710 100644 --- a/doric-Qt/example/doric/resources/flex.qml +++ b/doric-Qt/example/doric/resources/flex.qml @@ -1,6 +1,6 @@ import QtQuick 2.12 import QtQuick.Controls 2.5 -import QtQuick.Layouts 1.15 +import QtQuick.Layouts 1.14 import QtGraphicalEffects 1.12 import "util.mjs" as Util diff --git a/doric-Qt/example/doric/resources/hlayout.qml b/doric-Qt/example/doric/resources/hlayout.qml index 21d48fa0..60536b9c 100644 --- a/doric-Qt/example/doric/resources/hlayout.qml +++ b/doric-Qt/example/doric/resources/hlayout.qml @@ -1,6 +1,6 @@ import QtQuick 2.12 import QtQuick.Controls 2.5 -import QtQuick.Layouts 1.15 +import QtQuick.Layouts 1.14 import QtGraphicalEffects 1.12 import "util.mjs" as Util diff --git a/doric-Qt/example/doric/resources/prompt.qml b/doric-Qt/example/doric/resources/prompt.qml index 71afd705..3e762654 100644 --- a/doric-Qt/example/doric/resources/prompt.qml +++ b/doric-Qt/example/doric/resources/prompt.qml @@ -1,6 +1,6 @@ import QtQuick 2.12 import QtQuick.Controls 2.12 -import QtQuick.Layouts 1.15 +import QtQuick.Layouts 1.14 ApplicationWindow { id: window diff --git a/doric-Qt/example/doric/resources/scroller.qml b/doric-Qt/example/doric/resources/scroller.qml index 02a630c7..00365328 100644 --- a/doric-Qt/example/doric/resources/scroller.qml +++ b/doric-Qt/example/doric/resources/scroller.qml @@ -1,6 +1,6 @@ import QtQuick 2.12 import QtQuick.Controls 2.5 -import QtQuick.Layouts 1.15 +import QtQuick.Layouts 1.14 import "util.mjs" as Util diff --git a/doric-Qt/example/doric/resources/slide-item.qml b/doric-Qt/example/doric/resources/slide-item.qml index c117d3fe..e18c4c40 100644 --- a/doric-Qt/example/doric/resources/slide-item.qml +++ b/doric-Qt/example/doric/resources/slide-item.qml @@ -1,6 +1,6 @@ import QtQuick 2.12 import QtQuick.Controls 2.5 -import QtQuick.Layouts 1.15 +import QtQuick.Layouts 1.14 import QtGraphicalEffects 1.12 import "util.mjs" as Util diff --git a/doric-Qt/example/doric/resources/stack.qml b/doric-Qt/example/doric/resources/stack.qml index c1cc6bf6..726f7b0a 100644 --- a/doric-Qt/example/doric/resources/stack.qml +++ b/doric-Qt/example/doric/resources/stack.qml @@ -1,6 +1,6 @@ import QtQuick 2.12 import QtQuick.Controls 2.5 -import QtQuick.Layouts 1.15 +import QtQuick.Layouts 1.14 import QtGraphicalEffects 1.12 import "util.mjs" as Util diff --git a/doric-Qt/example/doric/resources/toast.qml b/doric-Qt/example/doric/resources/toast.qml index a5702e2d..d39df491 100644 --- a/doric-Qt/example/doric/resources/toast.qml +++ b/doric-Qt/example/doric/resources/toast.qml @@ -1,6 +1,6 @@ import QtQuick 2.12 import QtQuick.Controls 2.5 -import QtQuick.Layouts 1.15 +import QtQuick.Layouts 1.14 ApplicationWindow { id: window diff --git a/doric-Qt/example/doric/resources/vlayout.qml b/doric-Qt/example/doric/resources/vlayout.qml index d642453f..0916ece7 100644 --- a/doric-Qt/example/doric/resources/vlayout.qml +++ b/doric-Qt/example/doric/resources/vlayout.qml @@ -1,6 +1,6 @@ import QtQuick 2.12 import QtQuick.Controls 2.5 -import QtQuick.Layouts 1.15 +import QtQuick.Layouts 1.14 import QtGraphicalEffects 1.12 import "util.mjs" as Util diff --git a/doric-Qt/example/doric/utils/DoricNetworkService.h b/doric-Qt/example/doric/utils/DoricNetworkService.h index dc2bdd28..63a57e21 100644 --- a/doric-Qt/example/doric/utils/DoricNetworkService.h +++ b/doric-Qt/example/doric/utils/DoricNetworkService.h @@ -10,6 +10,7 @@ #include #include "DoricExport.h" +#include "ReplyTimeout.h" class DORIC_EXPORT InnerTask : public QObject { Q_OBJECT @@ -37,14 +38,14 @@ public: } } - if (timeoutVal.isDouble()) { - networkAccessManager.setTransferTimeout(timeoutVal.toInt()); - } - if (method == "get") { httpRequest.setUrl(QUrl(url)); QNetworkReply *reply = networkAccessManager.get(httpRequest); + if (timeoutVal.isDouble()) { + ReplyTimeout::set(reply, timeoutVal.toInt()); + } + connect(reply, &QNetworkReply::finished, this, [this, reply] { int statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); diff --git a/doric-Qt/example/doric/utils/ReplyTimeout.h b/doric-Qt/example/doric/utils/ReplyTimeout.h new file mode 100644 index 00000000..96410a4b --- /dev/null +++ b/doric-Qt/example/doric/utils/ReplyTimeout.h @@ -0,0 +1,46 @@ +#ifndef REPLYTIMEOUT_H +#define REPLYTIMEOUT_H + +#include +#include +#include +#include + +#include "DoricExport.h" + +class DORIC_EXPORT ReplyTimeout : public QObject { + Q_OBJECT +public: + enum HandleMethod { Abort, Close }; + ReplyTimeout(QNetworkReply *reply, const int timeout, + HandleMethod method = Abort) + : QObject(reply), m_method(method) { + Q_ASSERT(reply); + if (reply && reply->isRunning()) { + m_timer.start(timeout, this); + connect(reply, &QNetworkReply::finished, this, &QObject::deleteLater); + } + } + static void set(QNetworkReply *reply, const int timeout, + HandleMethod method = Abort) { + new ReplyTimeout(reply, timeout, method); + } + +protected: + QBasicTimer m_timer; + HandleMethod m_method; + void timerEvent(QTimerEvent *ev) { + if (!m_timer.isActive() || ev->timerId() != m_timer.timerId()) + return; + auto reply = static_cast(parent()); + if (reply->isRunning()) { + if (m_method == Close) + reply->close(); + else if (m_method == Abort) + reply->abort(); + m_timer.stop(); + } + } +}; + +#endif // REPLYTIMEOUT_H