From a77433f8810c100e6934c64afe9d69c6c0cff2f4 Mon Sep 17 00:00:00 2001 From: Silarn Date: Fri, 4 May 2018 14:28:19 -0500 Subject: Use queued connections and do while loops to finish event processing --- src/installationmanager.cpp | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) (limited to 'src/installationmanager.cpp') diff --git a/src/installationmanager.cpp b/src/installationmanager.cpp index a99a07e1..27c83787 100644 --- a/src/installationmanager.cpp +++ b/src/installationmanager.cpp @@ -96,8 +96,8 @@ InstallationManager::InstallationManager() throw MyException(getErrorString(m_ArchiveHandler->getLastError())); } - connect(this, SIGNAL(progressUpdate(float)), this, (SLOT(doProgressUpdate(float)))); - connect(this, SIGNAL(progressUpdate(const QString)), this, (SLOT(doProgressFileUpdate(const QString)))); + connect(this, SIGNAL(progressUpdate(float)), this, (SLOT(doProgressUpdate(float))), Qt::QueuedConnection); + connect(this, SIGNAL(progressUpdate(const QString)), this, (SLOT(doProgressFileUpdate(const QString))), Qt::QueuedConnection); } InstallationManager::~InstallationManager() @@ -202,10 +202,10 @@ bool InstallationManager::unpackSingleFile(const QString &fileName) new MethodCallback(this, &InstallationManager::report7ZipError) ); }); - while (!future.isFinished()) { - QCoreApplication::processEvents(); + do { ::Sleep(50); - } + QCoreApplication::processEvents(); + } while (!future.isFinished()); bool res = future.result(); return res; @@ -300,10 +300,10 @@ QStringList InstallationManager::extractFiles(const QStringList &filesOrig, bool new MethodCallback(this, &InstallationManager::report7ZipError) ); }); - while (!future.isFinished()) { - QCoreApplication::processEvents(); + do { ::Sleep(50); - } + QCoreApplication::processEvents(); + } while (!future.isFinished()); if (!future.result()) { throw MyException(QString("extracting failed (%1)").arg(m_ArchiveHandler->getLastError())); } @@ -444,7 +444,7 @@ void InstallationManager::updateProgressFile(QString const &fileName) void InstallationManager::doProgressUpdate(float percentage) { if (m_InstallationProgress != nullptr) { - QMetaObject::invokeMethod(this, "setProgressValue", Qt::QueuedConnection, Q_ARG(int, static_cast(percentage * 100.0))); + m_InstallationProgress->setValue(static_cast(percentage * 100.0)); if (m_InstallationProgress->wasCanceled()) { m_ArchiveHandler->cancel(); @@ -453,13 +453,6 @@ void InstallationManager::doProgressUpdate(float percentage) } } -void InstallationManager::setProgressValue(int percentage) -{ - if (m_InstallationProgress != nullptr) { - m_InstallationProgress->setValue(percentage); - } -} - void InstallationManager::doProgressFileUpdate(QString const fileName) { if (m_InstallationProgress != nullptr) { @@ -616,10 +609,10 @@ bool InstallationManager::doInstall(GuessedValue &modName, QString game new MethodCallback(this, &InstallationManager::report7ZipError) ); }); - while (!future.isFinished()) { - QCoreApplication::processEvents(); + do { ::Sleep(50); - } + QCoreApplication::processEvents(); + } while (!future.isFinished()); if (!future.result()) { if (m_ArchiveHandler->getLastError() == Archive::ERROR_EXTRACT_CANCELLED) { return false; -- cgit v1.3.1