nix
nix

Reputation: 2285

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?

Upvotes: 0

Views: 2587

Answers (3)

user7053279
user7053279

Reputation: 1

If you add below command to .pro file you will able to compile it.

INCLUDEPATH += ...path/Views/

Upvotes: 0

Lahiru Chandima
Lahiru Chandima

Reputation: 24128

Documentation doesn't say that HEADERS is for specifying include paths to the compiler. HEADERS is used for generating dependency information and checking whether moc is necessary.

Upvotes: 0

G. Ko
G. Ko

Reputation: 403

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"

Upvotes: 3

Related Questions