diff options
author | Giuseppe D'Angelo <[email protected]> | 2025-03-14 15:31:48 +0100 |
---|---|---|
committer | Giuseppe D'Angelo <[email protected]> | 2025-03-17 20:41:29 +0100 |
commit | 585471b138b195cb9020200cae760f119903df85 (patch) | |
tree | 1e4c45df813311dfd1dd9f1ecdcf93c97e129d20 | |
parent | 0eba6478eefcc7ef7591e75f95002a36a0685343 (diff) |
Fix calls to non-started QElapsedTimer functions
It's illegal to call elapsed() or restart() (sic) on a non-started
QElapsedTimer, so don't do that. In QNAM code, this has been observed by
adding assertions into QElapsedTimer, which then make network tests
crash. (While I am unable to run the network testsuite, this is
reproducible locally by running tst_QNetworkDiskCache::setCookieHeader).
The QTextStream test also calls restart() without a start(), but then it
calls elapsed()+start() which is the whole point of restart(), so amend
accordingly.
Pick-to: 6.9 6.8 6.5
Change-Id: I5cfe308f64b631b68b92843b409777a6b9176828
Reviewed-by: Marc Mutz <[email protected]>
Reviewed-by: Thiago Macieira <[email protected]>
-rw-r--r-- | src/network/access/qnetworkreplyhttpimpl.cpp | 9 | ||||
-rw-r--r-- | tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp | 10 |
2 files changed, 10 insertions, 9 deletions
diff --git a/src/network/access/qnetworkreplyhttpimpl.cpp b/src/network/access/qnetworkreplyhttpimpl.cpp index 5a0cd052782..cf4d5f1f4ff 100644 --- a/src/network/access/qnetworkreplyhttpimpl.cpp +++ b/src/network/access/qnetworkreplyhttpimpl.cpp @@ -1168,7 +1168,8 @@ void QNetworkReplyHttpImplPrivate::replyDownloadData(QByteArray d) emit q->readyRead(); // emit readyRead before downloadProgress in case this will cause events to be // processed and we get into a recursive call (as in QProgressDialog). - if (downloadProgressSignalChoke.elapsed() >= progressSignalInterval + if (downloadProgressSignalChoke.isValid() && + downloadProgressSignalChoke.elapsed() >= progressSignalInterval && (!decompressHelper.isValid() || decompressHelper.isCountingBytes())) { downloadProgressSignalChoke.restart(); emit q->downloadProgress(bytesDownloaded, totalSizeOpt.value_or(-1)); @@ -1501,7 +1502,8 @@ void QNetworkReplyHttpImplPrivate::replyDownloadProgressSlot(qint64 bytesReceive // processed and we get into a recursive call (as in QProgressDialog). if (bytesDownloaded > 0) emit q->readyRead(); - if (downloadProgressSignalChoke.elapsed() >= progressSignalInterval) { + if (downloadProgressSignalChoke.isValid() && + downloadProgressSignalChoke.elapsed() >= progressSignalInterval) { downloadProgressSignalChoke.restart(); emit q->downloadProgress(bytesDownloaded, bytesTotal); } @@ -1938,7 +1940,8 @@ void QNetworkReplyHttpImplPrivate::_q_cacheLoadReadyRead() // This readyRead() goes to the user. The user then may or may not read() anything. emit q->readyRead(); - if (downloadProgressSignalChoke.elapsed() >= progressSignalInterval) { + if (downloadProgressSignalChoke.isValid() && + downloadProgressSignalChoke.elapsed() >= progressSignalInterval) { downloadProgressSignalChoke.restart(); emit q->downloadProgress(bytesDownloaded, totalSizeOpt.value_or(-1)); } diff --git a/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp b/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp index 25183fccd76..1a3d161e788 100644 --- a/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp +++ b/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp @@ -987,7 +987,7 @@ void tst_QTextStream::performance() }; int elapsed[N] = {0, 0, 0}; - stopWatch.restart(); + stopWatch.start(); int nlines1 = 0; QFile file(m_rfc3261FilePath); QVERIFY(file.open(QFile::ReadOnly)); @@ -997,8 +997,7 @@ void tst_QTextStream::performance() file.readLine(); } - elapsed[0] = stopWatch.elapsed(); - stopWatch.restart(); + elapsed[0] = stopWatch.restart(); int nlines2 = 0; QFile file2(m_rfc3261FilePath); @@ -1010,8 +1009,7 @@ void tst_QTextStream::performance() stream.readLine(); } - elapsed[1] = stopWatch.elapsed(); - stopWatch.restart(); + elapsed[1] = stopWatch.restart(); int nlines3 = 0; QFile file3(m_rfc3261FilePath); @@ -1022,7 +1020,7 @@ void tst_QTextStream::performance() while (stream2.readLineInto(&line)) ++nlines3; - elapsed[2] = stopWatch.elapsed(); + elapsed[2] = stopWatch.restart(); QCOMPARE(nlines1, nlines2); QCOMPARE(nlines2, nlines3); |