From 8cebb36a9c40270cc0cc7126b535c9031f4b3418 Mon Sep 17 00:00:00 2001 From: Simon Quigley Date: Thu, 25 Jan 2024 13:32:09 -0600 Subject: [PATCH] Invoke setEnabled less, which will help with resource usage It is slightly more resource efficient to create a local bool, update that one-way flag when needed, and then setEnabled based on the content of that bool, than it would be to call that method every time. --- mainwindow.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index b4a27b0..54fe954 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -43,9 +43,10 @@ void MainWindow::setUpdateInfo(QList updateInfo) ui->closeButton->setEnabled(true); ui->installButton->setEnabled(false); // Correct, it starts out false, we turn it to true if there are any updates. + bool installEnabled = false; for (int i = 0;i < 4;i++) { if (updateInfo[i].count() > 0) { - ui->installButton->setEnabled(true); + installEnabled = true; } QTreeWidgetItem *installItem; @@ -74,6 +75,8 @@ void MainWindow::setUpdateInfo(QList updateInfo) ui->statLabel->setText(QString("%1 package(s) will be updated. %2 of these updates are security-related.") .arg(QString::number(updateInfo[0].count() + updateInfo[1].count() + updateInfo[2].count()), QString::number(updateInfo[4].count()))); + + ui->installButton->setEnabled(installEnabled); } bool MainWindow::isLockedOpen()