Why might the Q_FOREACH macro break VS2010 intellisense?

后端 未结 1 1154
情话喂你
情话喂你 2021-01-18 02:52

I have a c++ project in VS2010 with Qt 4.7.4 and I frequently have problems with IntelliSense (as we all do...). A specific problem is that sometimes the function body (in t

相关标签:
1条回答
  • 2021-01-18 03:10

    You have to use the concept of 'cpp.hint' files.

    Basically, you have to put the troublesome macros into a file named 'cpp.hint' and put that file in your solution directory (which did not work for me - non-standard project layout maybe) OR in a parent-directory where your code files reside in. (worked for me)

    In that file you just put the troublesome macros WITHOUT right-hand-side, so in your case:

    #define foreach()
    

    or maybe better

    #define Q_FOREACH(variable, container)
    #define foreach(...)
    etc.
    

    NOTE, that you may have to ReScan or Restart or fiddle around with a function for the effect to set in after putting the definition in the cpp.hint file.

    UPDATE: Indeed, I just found, that I have to make some change to a .cpp file (e.g. adding a new line) for the effect to kick in. The fix is not automatically applied.

    The original link is: http://msdn.microsoft.com/en-us/library/dd997977.aspx

    The reason for the trouble is that Intellisense performance would (potentially) decrease dramatically if it had to parse all macros in a project, so it only parses those given explicitly in 'cpp.hint'.

    The original microsoft text says that you can use any directory in "The path from the root directory of a source file to the directory that contains the source file itself. In a typical Visual C++ project, the root directory contains the solution or project file."

    You can find the main 'cpp.hint' file at 'C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcpackages' for reference

    0 讨论(0)
提交回复
热议问题