为什么Qt Creator在包含的路径中找不到包含的标题 - 即使qmake能够找到它们 [英] Why doesn't Qt Creator find included headers in included paths - even though qmake is able to find them

查看:340
本文介绍了为什么Qt Creator在包含的路径中找不到包含的标题 - 即使qmake能够找到它们的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我加入了一个已经存在的(opensource-)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 行添加到搜索路径中。如果我将鼠标悬停在项目的.h文件中的 #includeextra.h,我总会得到一个弹出窗口extra.h:没有这样的文件或目录。

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".

在KDevelop中没有问题,而且qmake也能得到它。什么是造物主的问题(我使用的是2.8,也试过3.0)

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)

任何帮助都非常感谢: - )

Any help greatly appreciated :-)

Konrad

编辑:我刚才意识到,整个Qt框架不被qt识别创作者也是。当我输入 #include时,自动完成建议的标题都位于/ usr / include或项目目录中。例如我甚至做不到 #include< QtGui>

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>.

这可能是什么问题?

EDIT2:项目文件还包括gui.pri和local.pri,它们也被其他几个项目使用。我试着稍微压缩文件 - 它仍然没有问题编译。

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.

实际项目文件位于dir0 / programs / us_convert

actual project file located in "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位于dir0 /

gui.pri located in "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 ..
}

和local.pri,也位于dir0 /

And local.pri, also located in "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

}


推荐答案

我知道我的答案已经很晚了,但我遇到了同样的问题,并且在很多不同的帖子中没有解决方案,但后来我找到了一个解决方案,对我来说:

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:

你必须在.pro文件中添加你正在使用的模块:

You have to add the module you are using in your .pro file:

例如,我想使用 #include< QtSql> 模块,但没有任何效果。
编译器找不到此文件。我发现我能够 #include< QtSql / QSqlDatabase> (以及在QtSql中声明的所有类型)然而,我得到了未定义参考错误。

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.

解决方案:你必须在你的.pro文件中添加你正在使用的模块,如下所示:

The Solution: You have to add the module you are using in you .pro file, in the following line:

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.

这适用于Windows以及Ubuntu!

This worked on Windows as well as on Ubuntu!

这篇关于为什么Qt Creator在包含的路径中找不到包含的标题 - 即使qmake能够找到它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆