Qt Creator can't find headers (says: “No such file or directory”)

前端 未结 6 1045
轻奢々
轻奢々 2021-02-05 10:11

How can I tell Qt Creator 2.4.1 (based on Qt 4.7.4 32-bit) where to look by default for header files?

When I open a C file in Qt Creator and say



        
6条回答
  •  星月不相逢
    2021-02-05 10:47

    I found myself often faced with this problem. I can reproduce it on my machine right now as well (Mac OS).

    It looks like QtCreator needs to have a project to correctly handle GCC path analysis (on top of Qt frameworks paths).
    The process Qt uses to find the headers is that it launches GCC (or your compiler on Windows) with special arguments that make it output the paths where the compiler finds its headers. BUT, to do that, it must have a project associated to your files, because it uses this project to determine what toolchain to use, thus where GCC is found.

    So the answer is this: create a project, always, to use the syntax analyzis.
    Note that it is quite important that when you create this project, you define which version of the Qt SDK and the toolchain you'll use, otherwise the syntax control-click won't work.

    You might find some interesting ways of using a Qt Project file although not using the Qt SDK or using Creator to build your project. See an answer to a similar question here: https://stackoverflow.com/a/5817226/389405

    Note that I personnally use this method, with a .pro file that simply lists all the subdirectories of my project, and with all keyboard shortcuts to build disabled, so that I only use Qt Creator as an editor. The syntax highlighting/linking is awesome and exceptionnally quick, far, far quicker than Eclipse!

    To do that, simply issue qmake -pro in the directory of your project. It will create a [DIR].pro file that you can remove any time.

    I filled a bug a year ago on an aspect of this syntax analyzis that was bothering me here: https://bugreports.qt.io/browse/QTCREATORBUG-4846, the reason beiing that the compiler I use output its data in French instead of English. They fixed the code in 2.4 but it might be Unix-specific (see the comments of the issue for more information) so you'll probably want to test if this issue can be applied to your case.

    If your issue continues even after creating a project for your edition, make sure to point it to the guys at qt-project.org !

    Otherwise, the only solution I see is modifying the source code of QtCreator. You can find in their last post some information about how to contribute here: https://blog.qt.io/blog/2012/03/15/qt-creator-2-5-beta/ (and try their new beta which supports C++ lambdas).

提交回复
热议问题