PipInstallTask: Connect to done() signal instead of finished()

Change-Id: I7a712791a440668c7efb8282d7f035a120c7d719
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Jarek Kobus
2022-06-20 16:32:36 +02:00
parent fc16aad2b4
commit a613caa234
2 changed files with 11 additions and 13 deletions

View File

@@ -47,10 +47,16 @@ namespace Internal {
static constexpr char pipInstallTaskId[] = "Python::pipInstallTask"; static constexpr char pipInstallTaskId[] = "Python::pipInstallTask";
PipInstallTask::PipInstallTask(const Utils::FilePath &python) PipInstallTask::PipInstallTask(const FilePath &python)
: m_python(python) : m_python(python)
{ {
m_watcher.setFuture(m_future.future()); m_watcher.setFuture(m_future.future());
connect(&m_process, &QtcProcess::done, this, &PipInstallTask::handleDone);
connect(&m_process, &QtcProcess::readyReadStandardError, this, &PipInstallTask::handleError);
connect(&m_process, &QtcProcess::readyReadStandardOutput, this, &PipInstallTask::handleOutput);
connect(&m_killTimer, &QTimer::timeout, this, &PipInstallTask::cancel);
connect(&m_watcher, &QFutureWatcher<void>::canceled, this, &PipInstallTask::cancel);
} }
void PipInstallTask::setPackage(const PipPackage &package) void PipInstallTask::setPackage(const PipPackage &package)
@@ -66,13 +72,6 @@ void PipInstallTask::run()
} }
const QString taskTitle = tr("Install %1").arg(m_package.displayName); const QString taskTitle = tr("Install %1").arg(m_package.displayName);
Core::ProgressManager::addTask(m_future.future(), taskTitle, pipInstallTaskId); Core::ProgressManager::addTask(m_future.future(), taskTitle, pipInstallTaskId);
connect(&m_process, &QtcProcess::finished, this, &PipInstallTask::installFinished);
connect(&m_process, &QtcProcess::readyReadStandardError, this, &PipInstallTask::handleError);
connect(&m_process, &QtcProcess::readyReadStandardOutput, this, &PipInstallTask::handleOutput);
connect(&m_killTimer, &QTimer::timeout, this, &PipInstallTask::cancel);
connect(&m_watcher, &QFutureWatcher<void>::canceled, this, &PipInstallTask::cancel);
QString package = m_package.packageName; QString package = m_package.packageName;
if (!m_package.version.isEmpty()) if (!m_package.version.isEmpty())
package += "==" + m_package.version; package += "==" + m_package.version;
@@ -102,13 +101,12 @@ void PipInstallTask::cancel()
.arg(m_package.displayName, m_killTimer.isActive() ? tr("user") : tr("time out"))); .arg(m_package.displayName, m_killTimer.isActive() ? tr("user") : tr("time out")));
} }
void PipInstallTask::installFinished() void PipInstallTask::handleDone()
{ {
m_future.reportFinished(); m_future.reportFinished();
const bool success = m_process.result() == ProcessResult::FinishedWithSuccess; const bool success = m_process.result() == ProcessResult::FinishedWithSuccess;
if (!success) { if (!success) {
Core::MessageManager::writeFlashing( Core::MessageManager::writeFlashing(tr("Installing the %1 failed with exit code %2")
tr("Installing the %1 failed with exit code %2")
.arg(m_package.displayName).arg(m_process.exitCode())); .arg(m_package.displayName).arg(m_process.exitCode()));
} }
emit finished(success); emit finished(success);
@@ -128,7 +126,7 @@ void PipInstallTask::handleError()
Core::MessageManager::writeSilently(stdErr); Core::MessageManager::writeSilently(stdErr);
} }
PipPackageInfo PipPackage::info(const Utils::FilePath &python) const PipPackageInfo PipPackage::info(const FilePath &python) const
{ {
PipPackageInfo result; PipPackageInfo result;

View File

@@ -84,7 +84,7 @@ signals:
private: private:
void cancel(); void cancel();
void installFinished(); void handleDone();
void handleOutput(); void handleOutput();
void handleError(); void handleError();