compatible with qt 5.14.2

This commit is contained in:
王劲鹏 2021-06-16 13:51:45 +08:00 committed by osborn
parent 50f80a3fe4
commit 6d100847e4
13 changed files with 62 additions and 14 deletions

View File

@ -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

View File

@ -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 \

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

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

View 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