C++ 为什么 Qt Creator 在包含的路径中找不到包含的头文件 - 即使 qmake 能够找到它们
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20701805/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why doesn't Qt Creator find included headers in included paths - even though qmake is able to find them
提问by user3122343
I joined an already existing (opensource-) Qt 4 project to add some functionality. The project compiles and runs perfectly on Linux Slackware with Qt 4.8.5. As IDE I first used KDevelop (comes with Slackware), but Qt project files aren't supported in KDevelop (since it primarily uses cmake, I had to use the makefile to import the project). Now I want to switch to Qt Creator, but header files in included (relative-) paths aren't recognized. For example the project file is in "dir0/programs/prog1/prog1.pro" and some extra headers are in "dir0/gui/extra.h". "dir0/gui" is added to the search path by the line INCLUDEPATH += ../../gui
in the project file. If I hover over #include "extra.h"
in a .h file of the project I always get a popup saying "extra.h: No such file or directory".
我加入了一个已经存在的(开源)Qt 4 项目来添加一些功能。该项目在带有 Qt 4.8.5 的 Linux Slackware 上编译并完美运行。作为IDE,我首先使用KDevelop(Slackware 自带),但KDevelop 不支持Qt 项目文件(因为它主要使用cmake,我不得不使用makefile 来导入项目)。现在我想切换到 Qt Creator,但无法识别包含(相对)路径中的头文件。例如,项目文件在“dir0/programs/prog1/prog1.pro”中,一些额外的头文件在“dir0/gui/extra.h”中。“dir0/gui”通过INCLUDEPATH += ../../gui
项目文件中的行添加到搜索路径中。如果我将鼠标悬停#include "extra.h"
在项目的 .h 文件中,我总是会弹出一个说“extra.h:没有这样的文件或目录”的弹出窗口。
In KDevelop there was no problem and also qmake gets it. What's the problem of the Creator (I'm using 2.8, and also tried 3.0)
在 KDevelop 中没有问题,qmake 也得到了它。Creator的问题是什么(我用的是2.8,也试过3.0)
Any help greatly appreciated :-)
非常感谢任何帮助:-)
Konrad
康拉德
EDIT: I just realized, that the whole Qt framework isn't recognized by qt-creator as well. When I type #include "
the headers suggested by auto-completion are all located either in "/usr/include" or the project directory. For example I even can't do #include <QtGui>
.
编辑:我刚刚意识到,qt-creator 也无法识别整个 Qt 框架。当我键入#include "
自动完成建议的标题时,它们都位于“/usr/include”或项目目录中。例如我什至做不到#include <QtGui>
。
what might be the problem here?
这里可能有什么问题?
EDIT2: The project file also includes gui.pri and local.pri which are used by several other projects as well. I tried to compress the files a bit - it still compiles without problems.
EDIT2:项目文件还包括其他几个项目也使用的 gui.pri 和 local.pri。我试图稍微压缩文件 - 它仍然可以毫无问题地编译。
actual project file located in "dir0/programs/us_convert"
位于“dir0/programs/us_convert”的实际项目文件
include( ../../gui.pri )
QT += xml
TARGET = us_convert
HEADERS = us_convert_gui.h \
us_convert.h \
us_convertio.h \
us_experiment.h \
us_experiment_gui.h \
us_selectbox.h \
us_intensity.h \
us_get_dbrun.h \
us_mwl_data.h
SOURCES = us_convert_gui.cpp \
us_convert.cpp \
us_convertio.cpp \
us_experiment.cpp \
us_experiment_gui.cpp \
us_selectbox.cpp \
us_intensity.cpp \
us_get_dbrun.cpp \
us_mwl_data.cpp
gui.pri located in "dir0/"
gui.pri 位于“dir0/”
# Profile include file for applications
!include( local.pri ) error( "local.pri is missing. Copy from local.pri.template and update variables as appropriate" )
TEMPLATE = app
DESTDIR = ../../bin
MOC_DIR = ./moc
OBJECTS_DIR = ./obj
VER = 10
CONFIG += $$DEBUGORRELEASE qt thread warn
unix {
LIBS += -L../../lib -lus_gui -lus_utils
LIBS += -lcrypto
LIBS += -lqwtplot3d-qt4 -lGLU
LIBS += -L$$MYSQLDIR -lmysqlclient
DEFINES += INTEL LINUX
INCLUDEPATH += $$MYSQLPATH ../../$$QWT3D/include
INCLUDEPATH += ../../gui ../../utils $$QWTPATH/include ..
}
And local.pri, also located in "dir0/"
而local.pri,也位于“dir0/”
DEBUGORRELEASE += debug
unix {
MYSQLPATH = /usr/include/mysql/
QWTPATH = /usr/local/qwt-5.2.2
SINGLEDIR = /usr/lib/qt/qt-solutions/qtsingleapplication/src
MYSQLDIR = /usr/include/mysql
QWT3D = /qwtplot3d-qt4/
LIBS += -L/usr/local/qwt-5.2.2/lib -lqwt
}
回答by Boris Month
I use premake and make to build my projects and QtCreator as IDE. I had the same problem as you, using the header-only Library GLM.
My source code containded the following line:
#include <glm/glm.hpp>
. It compiled without errors, but QT-Creator couldn't find the file, so I was not able to jump to it or functions it contains by holding CTRL and clicking on some function the library provided.
我使用 premake 和 make 来构建我的项目和 QtCreator 作为 IDE。我和你有同样的问题,使用仅标头库 GLM。我的源代码包含以下行:
#include <glm/glm.hpp>
. 它编译没有错误,但 QT-Creator 找不到该文件,所以我无法通过按住 CTRL 键并单击库提供的某些函数来跳转到它或它包含的函数。
In my project folder ther is a file called "Tree.includes", where "Tree" is the name of my QT-Creator project. I had to add the path to the library I use ther and it worked.
在我的项目文件夹中有一个名为“Tree.includes”的文件,其中“Tree”是我的 QT-Creator 项目的名称。我必须添加到我使用的库的路径并且它起作用了。
usedLibraries/glm/
usedLibraries/glm/
My "Tree.includes" file looks like this:
我的“Tree.includes”文件如下所示:
project/src
usedLibraries/glm/
usedLibraries/glew-1.11.0/include/
usedLibraries/glfw-3.0.4/include/
My project folder lookes like this:
我的项目文件夹如下所示:
.
├── project
│?? ├── bin
│?? ├── build
│?? ├── gcc.txt
│?? ├── include
│?? ├── Makefile
│?? ├── premake4.lua
│?? └── src
├── Tree.config
├── Tree.creator
├── Tree.creator.user
├── Tree.files
├── Tree.includes
└── usedLibraries
├── glew-1.11.0
├── glfw-3.0.4
└── glm
回答by ElectRocnic
I know my answer is late, but I had the same problem and there was no solution in tons of different posts, but then I found a solution, which worked for me:
我知道我的回答晚了,但我遇到了同样的问题,并且在大量不同的帖子中都没有解决方案,但后来我找到了一个对我有用的解决方案:
You have to add the module you are using in your .pro file:
您必须在 .pro 文件中添加您正在使用的模块:
For example, I wanted to use the #include<QtSql>
module, but nothing worked.
The compiler did not find this file. I found out that I was able to #include<QtSql/QSqlDatabase>
(and all types which are declared in QtSql) however, but then I got an "undefined reference"
error.
例如,我想使用该#include<QtSql>
模块,但没有任何效果。编译器没有找到这个文件。我发现我能够#include<QtSql/QSqlDatabase>
(以及在 QtSql 中声明的所有类型),但是后来出现"undefined reference"
错误。
The Solution:You have to add the module you are using in you .pro file, in the following line:
解决方案:您必须在 .pro 文件中添加您正在使用的模块,如下行:
QT = core gui
(This is how it looked by default for me) This is how it looks now for me and how it worked for me:
(这是我默认的样子)这是我现在的样子以及它对我的工作方式:
QT = core gui sql
Hope this helps somebody else who has got the same issues.
希望这可以帮助其他遇到相同问题的人。
This worked on Windows as well as on Ubuntu!
这适用于 Windows 以及 Ubuntu!
回答by Abhishek Bansal
You should include the HEADERS also in the .pro file.
您还应该在 .pro 文件中包含 HEADERS。
HEADERS += ../../gui/extra.h
After doing this, save your project, let it parse. Then deleteyour existing build folder (do not just clean), and then try to re-build.
执行此操作后,保存您的项目,让它解析。然后删除您现有的构建文件夹(不要只是清理),然后尝试重新构建。
回答by MoreMag
i had same problem my problem was an empty line between headers and source :
我有同样的问题我的问题是标题和源之间的空行:
HEADERS += \
#<- 1- this line was first problem
blabla.h \ #<- 2- and added $$PWD here too
i changed it to this :
我把它改成这样:
INCLUDEPATH += $$PWD
HEADERS += \
$$PWD/qquickgridstar.h \