"Multiple parse contexts" in Qt creator
-
Not sure what is meant here:
This comes from Qt creator latest version 4.3.1 on windows 10,in case it matters.
I am at a loss what I can do to get rid of it. Obviously, I can use "Do Not Show Again" which is on the right of the message, but I prefer to know, what I am ignoring.
What are possible causes?
-
Most likely you have multiple (Sub-)projects containg this file. Depending on the parse context, different defines may be active that influence the parsing of this file
-
Hi
Do you use sessions?
https://bugreports.qt.io/browse/QTCREATORBUG-18521Anyway, its not clear from source what is being checked
CppTools::BaseEditorDocumentProcessor *CppEditorDocument::processor() { ... const bool isAmbiguous = info.hints & ProjectPartInfo::IsAmbiguousMatch; const bool isProjectFile = info.hints & ProjectPartInfo::IsFromProjectMatch; showHideInfoBarAboutMultipleParseContexts(isAmbiguous && isProjectFile); // this shows msg
The IsFromProjectMatch flag is set here
cppprojectpartchooser.cpp// Hints if (m_info.projectParts.size() > 1) m_info.hints |= ProjectPartInfo::IsAmbiguousMatch; if (prioritized.first().priority > 1000) m_info.hints |= ProjectPartInfo::IsPreferredMatch; if (areProjectPartsFromDependencies) m_info.hints |= ProjectPartInfo::IsFromDependenciesMatch; else m_info.hints |= ProjectPartInfo::IsFromProjectMatch;
so it seems to be related to sort / classify files depending on origin but didnt really see the meaning of
multiple contexts.update: yep, as @aha_1980 says, sub projects might trigger this , it seems from the code.
[Added code tags ~kshegunov]
-
Thanks guys.
Yes, I am using subprojects.
Yes, I am using sessions.Within the session I have/had a couple of projects which I have also put into a subdirs project,which is also open.
Apparently the message is an one time display, because it does not vanish after:
- closing the duplicates
- changing to another file
I was using a search over all projects with some text. That might have triggered the message.
I guess for the first time, it might make sense for a file. However, when switching to another file, the meaning is lost, because the message refers to "this file".The description of the bug report does not really fit my case.
How can I choose a prefered one then?
-
you can select the active parse context with drop down box (3) from http://doc.qt.io/qtcreator/creator-coding-navigating.html
-
Thanks for link. That is exactly what I was looking for.
As a side note, the dropdown box is not always visible. I had realized that there was something, but could not really make it out. In addition the content was not obviously related to my issue. Probably, I have seen the box the first time in that context.
IMHO the warning text is ambigious, which causes confusion. However, rather than just complaining about it, which is always easy, I cannot offer an alternative text. -
No subprojects. No sessions. Choosing C++ from the Parse Contect drop down does nothing.
From what I can tell the reason that this is badly broken is that the GUI only lets you choose between C and C++ to resolve "parse contexts". Looking at the source "ProjectPart" has the following fields, and it is totally opaque from the GUI as to why a file has more than one of these ProjectParts
public:
ProjectExplorer::Project *project = nullptr;QString displayName; QString projectFile; int projectFileLine = -1; int projectFileColumn = -1; QString callGroupId; // Versions, features and extensions ::Utils::Language language = ::Utils::Language::Cxx; ::Utils::LanguageVersion languageVersion = ::Utils::LanguageVersion::LatestCxx; ::Utils::LanguageExtensions languageExtensions = ::Utils::LanguageExtension::None; CPlusPlus::LanguageFeatures languageFeatures; ::Utils::QtVersion qtVersion = ::Utils::QtVersion::Unknown; // Files ProjectFiles files; QStringList includedFiles; QStringList precompiledHeaders; ProjectExplorer::HeaderPaths headerPaths; QString projectConfigFile; // Generic Project Manager only // Macros ProjectExplorer::Macros projectMacros; ProjectExplorer::Macros toolChainMacros; // Build system QString buildSystemTarget; ProjectExplorer::BuildTargetType buildTargetType = ProjectExplorer::BuildTargetType::Unknown; bool selectedForBuilding = true; // ToolChain Utils::Id toolchainType; bool isMsvc2015Toolchain = false; QString toolChainTargetTriple; ToolChainWordWidth toolChainWordWidth = WordWidth32Bit; ::Utils::FilePath toolChainInstallDir; ::Utils::WarningFlags warningFlags = ::Utils::WarningFlags::Default; // Misc QStringList extraCodeModelFlags; QStringList compilerFlags;