Nika Gamkrelidze Nika Gamkrelidze - 1 month ago 16
C++ Question

Qt compiler cannot find the header file

I know it's a quite common issue but I haven't found a comprehensive answer on the following question.
I have Qt 5.4.1 MSVC2013 build running on Windows 8.1.
Here is a look on my project files:

enter image description here

And here is what my .pro file looks like:

QT += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = Vfp
TEMPLATE = app

QMAKE_CXXFLAGS = - std=c++11

SOURCES += main.cpp\
Views/mainview.cpp

HEADERS += Views/mainview.h

FORMS += Views/mainview.ui


The problem is, unless I add
INCLUDEPATH += Views/
to the .pro file, I cannot include
mainview.h
in
main.cpp
file.

Why? Shouldn't
HEADERS += Views/mainview.h
be enough?

Answer

If you're including the header file this way:

#include "mainview.h"

Then yes, you need to add that include path since the compiler (not the IDE) doesn't know where mainview.h is. Otherwise, you need to specify the relative path to the file, like:

#include "Views/mainview.h"
Comments