Search code examples
c++qtvimautocompleteclang

How to enable autocomplete for Qt code in Vim


I've been searching around for a while, but I can't find a source to where I can make Vim c++ autocomplete Qt classes, functions, etc.

Clang complete works using SFML and the standard C++ libraries, I don't understand why it doesn't work with Qt.


Solution

  • You have to tell clang where to look for the Qt header files. This is done with the -I/path/to/headers flag. You can specific compiler flags for a specific project by adding them to a file named .clang_complete in your project's directory. Basically any compiler flags used to compile your code must be in your .clang_complete file. For example for Qt my .clang_complete file contains

    -I/usr/local/include/QtCore
    -I/usr/local/include/QtOpenGL
    -I/usr/local/include/QtGui
    

    clang_complete also includes a script to automatically generate .clang_complete files. clang_complete's help file describes how to use it. You can also type the command :help clang_complete in vim to access the help.