QmlPreview: Don't use MainFileAspect if it doesn't exist

We only need to choose the main file if we're dealing with a qmlproject.

Fixes: QTCREATORBUG-24056
Change-Id: I5b5dfa29a46fa07de7ee570fa033d978e72dfdb5
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Ulf Hermann
2020-05-20 18:44:45 +02:00
parent 036e8611eb
commit 20c387f636

View File

@@ -134,21 +134,22 @@ LocalQmlPreviewSupport::LocalQmlPreviewSupport(ProjectExplorer::RunControl *runC
const auto currentTarget = runControl->target(); const auto currentTarget = runControl->target();
const auto *qmlBuildSystem = qobject_cast<QmlProjectManager::QmlBuildSystem *>(currentTarget->buildSystem()); const auto *qmlBuildSystem = qobject_cast<QmlProjectManager::QmlBuildSystem *>(currentTarget->buildSystem());
const auto aspect = runControl->aspect<QmlProjectManager::QmlMainFileAspect>(); if (const auto aspect = runControl->aspect<QmlProjectManager::QmlMainFileAspect>()) {
const QString mainScript = aspect->mainScript(); const QString mainScript = aspect->mainScript();
const QString currentFile = aspect->currentFile(); const QString currentFile = aspect->currentFile();
const QString mainScriptFromProject = qmlBuildSystem->targetFile( const QString mainScriptFromProject = qmlBuildSystem->targetFile(
Utils::FilePath::fromString(mainScript)).toString(); Utils::FilePath::fromString(mainScript)).toString();
const QString currentFileFromProject = qmlBuildSystem->targetFile( const QString currentFileFromProject = qmlBuildSystem->targetFile(
Utils::FilePath::fromString(currentFile)).toString(); Utils::FilePath::fromString(currentFile)).toString();
if (!currentFile.isEmpty() && qmlProjectRunConfigurationArguments.last().contains(mainScriptFromProject)) { if (!currentFile.isEmpty() && qmlProjectRunConfigurationArguments.last().contains(mainScriptFromProject)) {
qmlProjectRunConfigurationArguments.removeLast(); qmlProjectRunConfigurationArguments.removeLast();
auto commandLine = Utils::CommandLine(runnable.commandLine().executable(), qmlProjectRunConfigurationArguments); auto commandLine = Utils::CommandLine(runnable.commandLine().executable(), qmlProjectRunConfigurationArguments);
commandLine.addArg(currentFile); commandLine.addArg(currentFile);
runnable.setCommandLine(commandLine); runnable.setCommandLine(commandLine);
}
} }
Utils::QtcProcess::addArg(&runnable.commandLineArguments, Utils::QtcProcess::addArg(&runnable.commandLineArguments,