Prevent precise timers from being used when unnecessary

The implementation of QTimer::singleShot() uses Qt::PreciseTimer if interval is less than 2 seconds. This isn't mentioned in the docs.
Qt::PreciseTimer increases the system's timer resolution which negatively affects power consumption.

PR #18555.
Closes #18350.
This commit is contained in:
Vladimir Golovnev 2023-02-14 08:26:08 +03:00 committed by sledgehammer999
commit df08bd331c
No known key found for this signature in database
GPG key ID: 6E4A2D025B7CC9A2
4 changed files with 4 additions and 4 deletions

View file

@ -283,7 +283,7 @@ void showSplashScreen()
painter.drawText(224 - painter.fontMetrics().horizontalAdvance(version), 270, version); painter.drawText(224 - painter.fontMetrics().horizontalAdvance(version), 270, version);
QSplashScreen *splash = new QSplashScreen(splashImg); QSplashScreen *splash = new QSplashScreen(splashImg);
splash->show(); splash->show();
QTimer::singleShot(1500ms, splash, &QObject::deleteLater); QTimer::singleShot(1500ms, Qt::CoarseTimer, splash, &QObject::deleteLater);
qApp->processEvents(); qApp->processEvents();
} }
#endif // DISABLE_GUI #endif // DISABLE_GUI

View file

@ -4929,7 +4929,7 @@ void SessionImpl::enqueueRefresh()
{ {
Q_ASSERT(!m_refreshEnqueued); Q_ASSERT(!m_refreshEnqueued);
QTimer::singleShot(refreshInterval(), this, [this] () QTimer::singleShot(refreshInterval(), Qt::CoarseTimer, this, [this]
{ {
m_nativeSession->post_torrent_updates(); m_nativeSession->post_torrent_updates();
m_nativeSession->post_session_stats(); m_nativeSession->post_session_stats();

View file

@ -503,7 +503,7 @@ void TorrentFilesWatcher::Worker::removeWatchedFolder(const Path &path)
void TorrentFilesWatcher::Worker::scheduleWatchedFolderProcessing(const Path &path) void TorrentFilesWatcher::Worker::scheduleWatchedFolderProcessing(const Path &path)
{ {
QTimer::singleShot(2s, this, [this, path]() QTimer::singleShot(2s, Qt::CoarseTimer, this, [this, path]
{ {
processWatchedFolder(path); processWatchedFolder(path);
}); });

View file

@ -94,7 +94,7 @@ void AppController::shutdownAction()
// Special handling for shutdown, we // Special handling for shutdown, we
// need to reply to the Web UI before // need to reply to the Web UI before
// actually shutting down. // actually shutting down.
QTimer::singleShot(100ms, qApp, []() QTimer::singleShot(100ms, Qt::CoarseTimer, qApp, []
{ {
QCoreApplication::exit(); QCoreApplication::exit();
}); });