illunara
illunara

Reputation: 337

Qt include header file from above directory

At first, i don't think this will become a problem, but after a few day working with it, i still can't find a solution

source
  |
  |--- Model
  |      |
  |      | - A.h
  |-B.h

I can't include the B.h from A.h, compiler complain that

"Cannot open include 'B.' : no such file or directory

And this is my .pro file

TEMPLATE = app
QT += qml quick widgets sql
QT += declarative
RESOURCES += qml.qrc
include(deployment.pri)
HEADERS += \
   sources/B.h \
   sources/model/A.h

A.h

#ifndef A_H
#define A_H
#include "source/B.h"
class A {
};
#endIf

B.h

#ifndef B_H
#define B_H
class B {

};
#endif

How can i fix this? And thank for dropping by

Upvotes: 0

Views: 2957

Answers (1)

Nejat
Nejat

Reputation: 32635

The path for include file is relative to the source file which is including it. So here in A.h you should have :

#include "../B.h"

Or add that path to the include directories by adding to .pro :

INCLUDEPATH += $$PWD/source

And include the header file like:

#include "B.h"

Upvotes: 2

Related Questions