From 2401eacdc7bd6072ac18ef4715c4b2e433bb57ef Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Mon, 2 Dec 2024 11:36:43 +0100 Subject: QtQml: Fix implementation of QQmlDataBlob::progress() We were dividing by 0xff twice, producing not percentages but 1/10000ths. Furthermore, the progressChanged() signaling from QQmlComponent was confused, often signaling a change when no actual change happened, or only signaling a change after it had already become perceptible to a user. Finally, QQmlDataBlob already caused too many callbacks to the progress change handler, which was especially silly because those have to travel across the thread boundary. Change-Id: Ifa09e4952a9213ef6290d8f3f3ab09d9f3f137df Reviewed-by: Fabian Kosmale --- src/quicktestutils/qml/testhttpserver.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'src/quicktestutils/qml/testhttpserver.cpp') diff --git a/src/quicktestutils/qml/testhttpserver.cpp b/src/quicktestutils/qml/testhttpserver.cpp index 4dfaf5acba..f6003b4a71 100644 --- a/src/quicktestutils/qml/testhttpserver.cpp +++ b/src/quicktestutils/qml/testhttpserver.cpp @@ -331,10 +331,21 @@ bool TestHTTPServer::reply(QTcpSocket *socket, const QByteArray &fileNameIn) m_toSend.append(qMakePair(socket, response)); QTimer::singleShot(500, this, &TestHTTPServer::sendOne); return false; - } else { + } + + if (response.length() <= m_chunkSize) { socket->write(response); return true; } + + socket->write(response.left(m_chunkSize)); + for (qsizetype offset = m_chunkSize, end = response.length(); offset < end; + offset += m_chunkSize) { + m_toSend.append(qMakePair(socket, response.mid(offset, m_chunkSize))); + } + + QTimer::singleShot(1, this, &TestHTTPServer::sendChunk); + return false; } } @@ -357,6 +368,16 @@ void TestHTTPServer::sendOne() } } +void TestHTTPServer::sendChunk() +{ + const auto chunk = m_toSend.takeFirst(); + chunk.first->write(chunk.second); + if (m_toSend.isEmpty()) + chunk.first->close(); + else + QTimer::singleShot(1, this, &TestHTTPServer::sendChunk); +} + void TestHTTPServer::serveGET(QTcpSocket *socket, const QByteArray &data) { const QHash::iterator it = m_dataCache.find(socket); -- cgit v1.2.3