compatible with qt 5.14.2
This commit is contained in:
parent
50f80a3fe4
commit
6d100847e4
@ -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
|
||||
|
@ -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 \
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include <QThread>
|
||||
|
||||
#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();
|
||||
|
46
doric-Qt/example/doric/utils/ReplyTimeout.h
Normal file
46
doric-Qt/example/doric/utils/ReplyTimeout.h
Normal file
@ -0,0 +1,46 @@
|
||||
#ifndef REPLYTIMEOUT_H
|
||||
#define REPLYTIMEOUT_H
|
||||
|
||||
#include <QBasicTimer>
|
||||
#include <QNetworkReply>
|
||||
#include <QObject>
|
||||
#include <QTimerEvent>
|
||||
|
||||
#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<QNetworkReply *>(parent());
|
||||
if (reply->isRunning()) {
|
||||
if (m_method == Close)
|
||||
reply->close();
|
||||
else if (m_method == Abort)
|
||||
reply->abort();
|
||||
m_timer.stop();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#endif // REPLYTIMEOUT_H
|
Reference in New Issue
Block a user