diff --git a/src/plugins/qmakeprojectmanager/externaleditors.cpp b/src/plugins/qmakeprojectmanager/externaleditors.cpp index 0d4791d028f..0b067e7a09b 100644 --- a/src/plugins/qmakeprojectmanager/externaleditors.cpp +++ b/src/plugins/qmakeprojectmanager/externaleditors.cpp @@ -25,6 +25,7 @@ #include "externaleditors.h" +#include #include #include #include @@ -142,23 +143,51 @@ QString ExternalQtEditor::displayName() const return m_displayName; } +static QString findFirstCommand(QVector qtVersions, + ExternalQtEditor::CommandForQtVersion command) +{ + foreach (QtSupport::BaseQtVersion *qt, qtVersions) { + if (qt) { + const QString binary = command(qt); + if (!binary.isEmpty()) + return binary; + } + } + return QString(); +} + bool ExternalQtEditor::getEditorLaunchData(const QString &fileName, LaunchData *data, QString *errorMessage) const { - // Get the binary either from the current Qt version of the project or Path - if (Project *project = SessionManager::projectForFile(Utils::FileName::fromString(fileName))) { + // Check in order for Qt version with the binary: + // - active kit of project + // - any other of the project + // - default kit + // - any other kit + // As fallback check PATH + data->workingDirectory.clear(); + QVector qtVersionsToCheck; // deduplicated after being filled + if (const Project *project = SessionManager::projectForFile(Utils::FileName::fromString(fileName))) { + data->workingDirectory = project->projectDirectory().toString(); + // active kit if (const Target *target = project->activeTarget()) { - if (const QtSupport::BaseQtVersion *qtVersion = QtSupport::QtKitInformation::qtVersion(target->kit())) { - data->binary = m_commandForQtVersion(qtVersion); - data->workingDirectory = project->projectDirectory().toString(); - } + qtVersionsToCheck << QtSupport::QtKitInformation::qtVersion(target->kit()); } + // all kits of project + qtVersionsToCheck += Utils::transform(project->targets(), [](Target *t) { + return QTC_GUARD(t) ? QtSupport::QtKitInformation::qtVersion(t->kit()) : nullptr; + }); } - if (data->binary.isEmpty()) { - data->workingDirectory.clear(); + // default kit + qtVersionsToCheck << QtSupport::QtKitInformation::qtVersion(KitManager::defaultKit()); + // all kits + qtVersionsToCheck += Utils::transform(KitManager::kits(), QtSupport::QtKitInformation::qtVersion); + qtVersionsToCheck = Utils::filteredUnique(qtVersionsToCheck); // can still contain nullptr + data->binary = findFirstCommand(qtVersionsToCheck, m_commandForQtVersion); + // fallback + if (data->binary.isEmpty()) data->binary = Utils::SynchronousProcess::locateBinary(m_commandForQtVersion(nullptr)); - } if (data->binary.isEmpty()) { *errorMessage = msgAppNotFound(id().toString()); return false; diff --git a/src/plugins/qmakeprojectmanager/externaleditors.h b/src/plugins/qmakeprojectmanager/externaleditors.h index d06026f28fd..5b2de682338 100644 --- a/src/plugins/qmakeprojectmanager/externaleditors.h +++ b/src/plugins/qmakeprojectmanager/externaleditors.h @@ -52,6 +52,9 @@ class ExternalQtEditor : public Core::IExternalEditor Q_OBJECT public: + // Member function pointer for a QtVersion function return a string (command) + using CommandForQtVersion = std::function; + static ExternalQtEditor *createLinguistEditor(); static ExternalQtEditor *createDesignerEditor(); @@ -69,9 +72,6 @@ public: }; protected: - // Member function pointer for a QtVersion function return a string (command) - using CommandForQtVersion = std::function; - ExternalQtEditor(Core::Id id, const QString &displayName, const QString &mimetype,