Is it possible to shorten the path of the .h files included by the .pri file?

1

I'm trying to separate my application from a small open lib I created, so I put the files in .pri and include in .pro , the folder structure looks like this:

c:/projetos/
├── minhalib
│   ├── minhalib.pri
│   ├── foo
│   |   ├── foo.cpp
│   |   └── foo.h
│   └── bar
│       ├── bar.cpp
│       └── bar.h
|
└── aplicativo
    ├── aplicativo.pro
    ├── main.cpp
    ├── mainwindow.cpp
    └── mainwindow.h

In the .pro application I have this:

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = aplicacao
TEMPLATE = app

SOURCES += main.cpp\
           mainwindow.cpp

HEADERS  += mainwindow.h

FORMS    += mainwindow.ui

include($PWD/../../minhalib/minhalib.pri)

And in minhalib/foo.pri I have this:

SOURCES  += $$PWD/foo/foo.cpp \
            $$PWD/bar/bar.cpp

HEADERS  += $$PWD/foo/foo.h \
            $$PWD/bar/bar.h

No main.cpp I called it like this:

#include "mainwindow.h"
#include "../minhalib/bar/bar.h"

#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    Bar bar;
    bar.test();

    MainWindow w;
    w.show();

    return a.exec();
}

Note that I include #include "../minhalib/bar/bar.h" , but I would like to include more simply something like:

#include <bar/bar>
#include <foo/foo>

Or:

#include "bar/bar.h"
#include "foo/foo.h"

How can I do this by setting in .pri

    
asked by anonymous 30.10.2016 / 21:53

1 answer

3

To solve, just use INCLUDEPATH += , in the specific case just point the path with $PWD

INCLUDEPATH += $$PWD

SOURCES  += $$PWD/foo/foo.cpp \
            $$PWD/bar/bar.cpp

HEADERS  += $$PWD/foo/foo.h \
            $$PWD/bar/bar.h

So the compiler recognizes paths like this:

#include "bar/bar.h"
#include "foo/foo.h"

A clue from colleague @Bacco to shorten more is to use to define the full path directly in INCLUDEPATH += , so for example:

INCLUDEPATH += $$PWD/foo \
               $$PWD/bar \

SOURCES  += $$PWD/foo/foo.cpp \
            $$PWD/bar/bar.cpp

HEADERS  += $$PWD/foo/foo.h \
            $$PWD/bar/bar.h

So do not just include it like this:

#include "bar.h"
#include "foo.h"

You need to be extra careful to check that there are no files of the same name in the directories listed

    
17.11.2016 / 00:28