Wrong Qt headers found by Qt Creator in edit mode
-
We recently began using Qt 5 with Qt Creator 2.7, on a CentOS 6.4 system. As you may know, CentOS requires Qt 4.6, so I can't remove it and I'm stuck with 2 Qt installations side by side.
I properly configured the Qt Version and the Desktop kit in the Qt Creator Build & Run options. I have also configured a set of environment variables in the .bashrc file as follows:
@#Qt-5.0.1 exports
export QTDIR="/workspace/third_party/libs/qt-5.0.1"
export PATH="${QTDIR}/bin:${PATH}"
export LD_LIBRARY_PATH="${QTDIR}/lib"
export CMAKE_PREFIX_PATH="${QTDIR}"
export PKG_CONFIG_PATH="${QTDIR}/lib/pkgconfig"@Builds complete successfully and run fine. Nonetheless, when coding, it seems that Qt Creator stills look in the /usr/include folder for header files when Shift+clicking Qt classes, and wrong entries appear in the code completion. I'm out of clues as to what I have done wrong and I am looking for any suggestions that could help me sort this out.
- EDIT -
The problem seems to occur only with Cmake projects.I'm not sure yet if this should be reported as a bug. It seems that working with projects using different Qt versions confuses the editor. Once a Qt4 project has been opened, the editor gets confused and finds files randomly in either the project's current kit include dir or the default include path (/usr/include on my system). However, the changes seem permanent!!! As if the session or the cmake projects manager stores some cache about the environment. Restarting Qt Creator and opening only a Qt5 project is not enough.
-
Your exports should not be necessary, the kit should set at least the PATH and LD_LIBRARY_PATH for you...
I did not hack on the Cmake code too much, but it basically works by running qmake and having that generate some files also used by codeblocks. Creator will then extract the information for the code model from there and will assume that the compiler from the Kit is actually used (which may or may not be the case, you can configure cmake as you like after all).
So can you check for (iirc) .cbp files or similar in your build dir? Which include paths are set there? Creator should just use the list found there.
-
Indeed, it seems that running Cmake inside Qt Creator adds some additional paths in the <Compiler> sections of the .cbp file.
Using only Qt Creator on a clean project (no .txt.user, CMakeCache files, .cbp files, etc..), I get something like this:
@ <Compiler>
<Add option="-DQT_WIDGETS_LIB" />
<Add option="-DQT_GUI_LIB" />
<Add option="-DQT_CORE_LIB" />
<Add directory="/usr/include" />
<Add directory="/usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6" />
<Add directory="/usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/backward" />
<Add directory="/usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/x86_64-redhat-linux" />
<Add directory="/usr/lib/gcc/x86_64-redhat-linux/4.4.6/include" />
<Add directory="/usr/local/include" />
<Add directory="/workspace/projects/qt-sandbox/MyProject" />
<Add directory="/workspace/projects/qt-sandbox/MyProject/build" />
<Add directory="/workspace/third_party/libs/opencv-2.4.5/include" />
<Add directory="/workspace/third_party/libs/qt-5.0.1/include" />
<Add directory="/workspace/third_party/libs/qt-5.0.1/include/QtCore" />
<Add directory="/workspace/third_party/libs/qt-5.0.1/include/QtGui" />
<Add directory="/workspace/third_party/libs/qt-5.0.1/include/QtWidgets" />
<Add directory="/workspace/third_party/libs/qt-5.0.1/mkspecs/linux-g++-64" />
</Compiler>@If I generate the files using cmake/ccmake and then I open the project with Qt Creator, I get:
@ <Compiler>
<Add option="-DQT_WIDGETS_LIB" />
<Add option="-DQT_GUI_LIB" />
<Add option="-DQT_CORE_LIB" />
<Add directory="/workspace/projects/qt-sandbox/MyProject" />
<Add directory="/workspace/projects/qt-sandbox/MyProject/build" />
<Add directory="/workspace/third_party/libs/opencv-2.4.5/include" />
<Add directory="/workspace/third_party/libs/qt-5.0.1/include" />
<Add directory="/workspace/third_party/libs/qt-5.0.1/include/QtCore" />
<Add directory="/workspace/third_party/libs/qt-5.0.1/include/QtGui" />
<Add directory="/workspace/third_party/libs/qt-5.0.1/include/QtWidgets" />
<Add directory="/workspace/third_party/libs/qt-5.0.1/mkspecs/linux-g++-64" />@The inclusion of <Add directory="/usr/include" /> probably causes the confusion (that's where the Qt 4.6 include files are located).