Skip to content

Commit

Permalink
Prevent precise timers from being used when unnecessary
Browse files Browse the repository at this point in the history
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 qbittorrent#18555.
Closes qbittorrent#18350.
  • Loading branch information
glassez authored and sledgehammer999 committed Feb 19, 2023
1 parent abd1ab5 commit df08bd3
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/app/main.cpp
Expand Up @@ -283,7 +283,7 @@ void showSplashScreen()
painter.drawText(224 - painter.fontMetrics().horizontalAdvance(version), 270, version);
QSplashScreen *splash = new QSplashScreen(splashImg);
splash->show();
QTimer::singleShot(1500ms, splash, &QObject::deleteLater);
QTimer::singleShot(1500ms, Qt::CoarseTimer, splash, &QObject::deleteLater);
qApp->processEvents();
}
#endif // DISABLE_GUI
Expand Down
2 changes: 1 addition & 1 deletion src/base/bittorrent/sessionimpl.cpp
Expand Up @@ -4929,7 +4929,7 @@ void SessionImpl::enqueueRefresh()
{
Q_ASSERT(!m_refreshEnqueued);

QTimer::singleShot(refreshInterval(), this, [this] ()
QTimer::singleShot(refreshInterval(), Qt::CoarseTimer, this, [this]
{
m_nativeSession->post_torrent_updates();
m_nativeSession->post_session_stats();
Expand Down
2 changes: 1 addition & 1 deletion src/base/torrentfileswatcher.cpp
Expand Up @@ -503,7 +503,7 @@ void TorrentFilesWatcher::Worker::removeWatchedFolder(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);
});
Expand Down
2 changes: 1 addition & 1 deletion src/webui/api/appcontroller.cpp
Expand Up @@ -94,7 +94,7 @@ void AppController::shutdownAction()
// Special handling for shutdown, we
// need to reply to the Web UI before
// actually shutting down.
QTimer::singleShot(100ms, qApp, []()
QTimer::singleShot(100ms, Qt::CoarseTimer, qApp, []
{
QCoreApplication::exit();
});
Expand Down

0 comments on commit df08bd3

Please sign in to comment.